I'm guessing that the error was happening because you were trying to call the code from a global function, but the code was using a this pointer, which is only valid within non-static class methods. You would still have problems if you move this code into a class because the Create method is expecting a non-NULL CWnd pointer, so creating it without a dialog would be difficult.
If you want to dynamically create the DSP control from a .DLL without a dialog, try adding the following line to your stadafx.h:
#import "cwanalysis.ocx" named_guids
Then in your code, make sure that COM has been initialized via CoInitialize, add #include "atlbase.h" to your source file, and use this code to create the DSP control:
// pwchLicenseKey is the valu
e that's copied and pasted from LICREQST.EXE
// See http://support.microsoft.com/default. aspx?scid=kb;en-us;151771
CComBSTR license(pwchLicenseKey);
CComPtr pClassFactory;
::CoGetClassObject(
CWAnalysisControlsLib::CLSID_CWDSP,
CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
0,
__uuidof(IClassFactory2),
reinterpret_cast(&pClassFactory)
);
CComPtr<:_DCWDSP> pDsp;
pClassFactory->CreateInstanceLic(
NULL,
NULL,
CWAnalysisControlsLib::DIID__DCWDSP,
license,
reinterpret_cast(&pDsp)
);
CComQIPtr pInit = pDsp;
pInit->InitNew();
// Call methods on pDsp ...
- Elton