Home > Back-end >  C builder COM type library calls appear memory error
C builder COM type library calls appear memory error

Time:09-18

To do a second development of software, the manufacturer provides a COM type of DLL library,
My way is:
1. The way of c + + builder to import the type library to generate xx_LIB. CPP and xx_LIB. J h,
2. The generated files added to the above project and # include xx_LIB. H
3. Then create an instance according to online and call a function, the code is as follows:
 void __fastcall TForm1: : Button1Click (TObject * Sender)//initialize the COM object and create an 
{
Retrieves the init.
Retrieves the hr;

Init=CoInitialize (NULL);//initialize the COM libraries
If (SUCCEEDED (init))
{
ShowMessage (" initialize COM object success ");
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
IRenishawDX10 * pDX10=NULL;//create an object
Hr=CoCreateInstance (Dx10sdkadaptorlib_tlb: : CLSID_DX10Adaptor, NULL, CLSCTX_INPROC_SERVER, Dx10sdkadaptorlib_tlb: : IID_IRenishawDX10, (void * *) & amp; PDX10);
If (SUCCEEDED (hr))
{
BSTR bstrSerNum=0;
VARIANT_BOOL bOK.

PDX10 - & gt; AddRef ();
Edit1 - & gt; Text="create COM objects success";
PDX10 - & gt; The Connect (& amp; BstrSerNum, & amp; BOK);//connection
PDX10 - & gt; Release ();
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CoUninitialize ();//terminate the COM library

}


But the problem is to run to the calling function namely pDX10 - & gt; The Connect (& amp; BstrSerNum, & amp; BOK); This row is memory error:

Access violation at 0 x7725fad5: write of address 0 x00030e70

CodePudding user response:

When calling a function parameter error?

CodePudding user response:

Check whether the variable type

CodePudding user response:

Recent OPC, also for COM headache, encountered a similar problem, I bring somebody else vs generated DLL BCB, can in the operation of the call is not normal

CodePudding user response:

BSTR bstrSerNum=0; Don't allocate space
  • Related