Mixed mode COM issues

  • Thread starter Thread starter andrew lowe
  • Start date Start date
A

andrew lowe

Hi,

Sorry for posting this in C# group as well as C++, but i'm desperate for
some guidance....

I want to create a mixed mode C++ dll that calls a COM object and returns a
managed string. I use the following steps but still get errors:
Created a new C++ .Net Class library project
Add the #import directive to my managed objects header file: #import
"C:\Documents and Settings\alowe\My Documents\ePathwayRequestBrokerDev.dll"
rename_namespace("ePathwayCOM")
Add a new method:

System::String* Execute(String* serviceName, String* xml) {
BSTR service = (BSTR)(void*)Marshal::StringToBSTR(serviceName);
BSTR message = (BSTR)(void*)Marshal::StringToBSTR(xml);
ePathwayCOM::_esyv0004Ptr broker;
broker->exec(service, message);
Marshal::FreeBSTR((void*)service);
Marshal::FreeBSTR((void*)message);
return "test";
}

Followed the instructions in
http://support.microsoft.com/default.aspx?scid=kb;en-us;814472 to make the
necessary project property changes
Added the ManagedWrapper class as stated in the instructions in the link
above
I then created a C# project to call the manged method however the call to
System::String* Execute(String* serviceName, String* xml); fails with a huge
COM error

Can anyone point out any mistakes i'm making please. I'm extremely desperate
to get his working
Thanks a billion in advance

andrew
 
Andrew,

You say it fails with a huge COM error. What is the error?

Also, when you debug, can you verify that your parameters are being
passed correctly?
 
Nicholas Paldino said:
Andrew,

You say it fails with a huge COM error. What is the error?

Also, when you debug, can you verify that your parameters are being
passed correctly?

Nicholas,

I've moved on from that error now and have a StackOverFlowException being
raised when i call the exec method:
BSTR service;
BSTR xml;
........
broker->exec(&service, &xml);

The compiler generated source file for the smart pointer class has the
definition
inline long _esyv0111::exec ( BSTR * servicename, BSTR * xml_message ) {
long _result = 0;
_com_dispatch_method(this, 0x3ea, DISPATCH_METHOD, VT_I4, (void*)&_result,
L"\x4008\x4008", servicename, xml_message);
return _result;
}

The weird thing is it only happens when the xml parameter starts returning a
string that is greater than roughly 600kb. The Com object is written in
Uniface so i can't change or look at the memory allocation inside of this
object. My c++ is rusty so i'm wondering if i'm calling the method in the
correct manner or if the 4mb of stack space is being abused ??. I can
guarentee that no recursion is taking place

thanks,
andrew
 
The stack space is by default 1MB. So it looks like "exec" is consuming all
the stack space when executing. Did you try to attach a debugger?

Willy.
 
Back
Top