Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

parameters for the create function in visual c++6

i want to use the create function to create the cwdsp dynamically in a visual c++ dll without a form. i only wnat to use the mathematical funtions of this activex. i tried it with the following line but it always produce an error:
m_Dsp.Create("", WS_VISIBLE, CRect(110,20,370,200),this, 0,NULL, FALSE, bstrLic);
0 Kudos
Message 1 of 5
(3,393 Views)
Try adding #include "atlbase.h" to your source file, then change your code to this:

// pwchLicenseKey is the value that's copied and pasted from LICREQST.EXE
// See http://support.microsoft.com/default.aspx?scid=kb;en-us;151771
CComBSTR license(pwchLicenseKey);
m_Dsp.Create(_T(""), 0, CRect(0, 0, 0, 0), this, 0, NULL, FALSE, license);

CComQIPtr init(m_Dsp.GetControlUnknown());
init->InitNew();

// Call methods on m_Dsp ...

- Elton
0 Kudos
Message 2 of 5
(3,393 Views)
the code you wrote produce the followind error.
this pointer is not allowed in global function. i tried the code without a form in a dll.

mike
0 Kudos
Message 3 of 5
(3,393 Views)
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
0 Kudos
Message 4 of 5
(3,393 Views)
i add the code you wrote to the initinstance method of the main file but it produced an internal compiler error (C1001). i work with visual studio 6 (professional) and component works 2.0.
0 Kudos
Message 5 of 5
(3,393 Views)