-
January 31st, 2005, 03:43 PM
#1
COM Error
Hi guys,
I have a COM exe server, which I added the following interface:
.h
[id(184), helpstring("method GetChange")] HRESULT GetChange([out] BSTR *pVal);
.cpp
STDMETHODIMP CATL::GetChange(BSTR *pVal)
{
CString strCommand;
bstr_t bstr( "Hello" );
*pVal = bstr.copy( );
return S_OK;
}
and I call it from my CLient like this:
BSTR Change;
ComObj->GetChange( & Change );
The problem is everytime I get to execute this instruction my application gets an access violation error and the callstack shows
RPCRT4! 7802e81c() as the method. It does not even get to the COM function, I debugged to make sure it's not the function that is causing this, any ideas why this is happening??/
Thanks a lot
-
January 31st, 2005, 07:27 PM
#2
Re: COM Error
Can you show all COM relevant code in your client? I want to see how you initialize your COM server.
Also, does your interface have any other methods? And if it does, are you able to call those methods successfully or not?
-
January 31st, 2005, 08:27 PM
#3
Re: COM Error
Hi JamesBond007,
Try this:
Code:
STDMETHODIMP CATL::GetChange(BSTR *pVal)
{
CString strCommand;
bstr_t bstr( "Hello" );
//*pVal = bstr.copy( );
::memcpy(pVal, bstr, bstr.length());
return S_OK;
}
Cheers
-
February 1st, 2005, 12:20 AM
#4
Re: COM Error
Thanks guys, but the problem is not in the code of the function, I put a breakpoint at the first instruction and it never reaches there.
my server has about 180 method and properties and they all work great, I just added this one method and it crashes the client whenever I make the call.
I get an access violation error. I'm thinking maybe the way I'm calling the interface, maybe I should not be using a BSTR as a param maybe a _bstr_t
while we're on the subject, is it possible for the COM interface to have a CSTring & param that the client can pass to it to get initialized??? as in [out].
Thanks
-
February 1st, 2005, 02:36 AM
#5
Re: COM Error
I would suggest using CComBSTR instead of bstr_t. Im not sure if its legal to use bstr_t in the way you are using it.
Edit: IIRC, COM does not allow the use of a bstr_t as an [out] parameter.
-
February 1st, 2005, 02:53 AM
#6
Re: COM Error
How did you add the Method? Did you use the IDE wizard or by hand. If by hand did you add the method to the IDL file?
-
February 1st, 2005, 09:03 AM
#7
Re: COM Error
I simply right clicked on the interface and add method, visual studio did all the rest.
tx
-
February 1st, 2005, 09:07 AM
#8
Re: COM Error
Can you post the IDL file to here for me to look at.
-
February 1st, 2005, 09:42 AM
#9
Re: COM Error
I know that you do not get into the code for the new method, but I keep seeing this:
Code:
BSTR Change;
ComObj->GetChange( & Change );
Change is just a pointer, no memory was allocated for this but your method will copy data into it. Will you change it to:
Code:
CComBSTR Change;
ComObj->GetChange( & Change );
-
February 1st, 2005, 09:54 AM
#10
Re: COM Error
Hi Mike200,
I removed the method and replaced it with a property and still get the same error.
basically the property is this :
.h
STDMETHOD(get_Change)(/*[out, retval]*/ BSTR *pVal);
.idl
[propget, id(186), helpstring("property Change")] HRESULT Change([out, retval] BSTR *pVal);
.cpp
STDMETHODIMP CSwitchConnectionATL::get_LastConfigChange(BSTR *pVal)
{
// TODO: Add your implementation code here
bstr_t bstr( "Hello", false);
*pVal = bstr.copy( );
return S_OK;
}
Thanks
-
February 1st, 2005, 10:10 AM
#11
Re: COM Error
How are you calling the method? Are you still passing in only a pointer or a pointer to a buffer??
Code:
CComBSTR Change;
ComObj->get_Change( & Change );
-
February 1st, 2005, 11:07 AM
#12
Re: COM Error
It's a property you don't pass a value, the property returns one.
_bstr_t = ComObj->Change;
I'm still thinking it has something to do with RPC since the error is return access violation and the call stack show the last call made was inside the RPCRT4 library.
Thanks
-
February 1st, 2005, 11:16 AM
#13
Re: COM Error
Ok, I checked the typelib in the OleView tools, and my property that I added is not there, any ideas , remind you it's not a COM dll in process so registration is done basically when launch the exe.
Thanks
-
February 1st, 2005, 11:29 AM
#14
Re: COM Error
Isn't registration of a COM exe done by passing RegServer on the command line? For your app would it be ComObj.exe RegServer. The _tWinMain function should have the code for this. Have you tried reregistering the server?
-
February 1st, 2005, 12:01 PM
#15
Re: COM Error
Hi Mike200,
Thanks for your patience, yes you're absolutely right, my problem I guess originated because I was having 2 versions of the server one that did not have the this method was registered, and when I added the method and compiled I launched the exe as you said but for some reason it did not update the entries of the interface in the typelib of OleView, I suspect because i did not speicify RegServer at the end of the command line, but now I did and it seems to have update the entries and it works fine.
Thanks for you feedback, appreciate it.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|