Again Hi Peter,
I"ve realised that I cannot do anything in Managed C++ because it
works through RCW's in the same way as C#. Instead I have written
an unmanaged C++ COM server (from which CoMarshalInterface
worked) and can call it from C#, wherein the conversion to raw COM
pointer happens by magic somewhere inside the RCW. It all seems
to work ok now thanks
Cheers
Bill
> Hi Peter,
>
[quoted text clipped - 4 lines]
> barrier. The samples I have examined (eg: the MCppWrapper example
> available from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/v
csammcppwrappersampledemonstrateswrappingcdllwithmanagedextensions.asp)
> show how to marshal some types between managed and unmanaged code.
> So far I havn't found an example that marshals a COM pointer.
[quoted text clipped - 33 lines]
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 27 Apr 2005 06:26 GMT
Hi Bill,
I am glat that you have figure your question our yourselves.
Yes, as your said if we write pure managed code in Managed C++, it will do
the same job with C#.(They are all based on CLR).
Also Managed C++ supported mixed mode code, that is to say, we can include
managed code together with unmanaged code( which is all in MCPP).
i.e. we call CoMarshalInterface in Unmanaged portion in the managed C++
Dll, while call the Unmanaged portion from Managed portion in the MCPP Dll.
e.g. call the api in managed class directly.
#include <windows.h>
#using <mscorlib.dll> //complied with /clr
__gc class MyTestWrap
{
public:
void ShowMessageBox()
{
MessageBox(NULL,"Hello","World",MB_OK);
}
System::String* GetModuleName()
{
HMODULE hInst = GetModuleHandle(NULL);
char hName[MAX_PATH];
DWORD sz=MAX_PATH;
if(GetModuleFileName(hInst,hName,sz)==0)
return new System::String("");
else
return new System::String(hName);
}
};
int _tmain(int argc, _TCHAR* argv[])
{
MyTestWrap* pObject = new MyTestWrap();
pObject->ShowMessageBox();
System::Console::WriteLine(pObject->GetModuleName());
return 0;
}
Also your approach is a solution too.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.