Passing Unmanaged object reference to Unmanaged method in C++/CLI managed method
I am getting exception when i am trying to pass unmanaged object, to COM method in method written in managed C++/CLI class. Following is the code sample
//C++/CLI class
public ref class PSIAAdaptorManagedWrapper
{
CConfiguration *Configuration;
void InitializeConfig();
}
//C++/CLI Method implementation
void PSIAAdaptorManagedWrapper::InitializeConfig() {
Configuration = new CConfiguration();
Configuration->IPAddress = "127.0.0.1";
Configuration->UserName = "User";
Configuration->password = "password";
SomeComObject->GetInitiConfig((void *) Configuration); // Exception line
}
//signature of COM object from IDL file (observer parame开发者_如何学Gor it takes is in)
[helpstring("method InitializeCameraConfig")]
HRESULT GetInitiConfig([in] void *configparam);
Above code compiles fine. But when execute I get "System.AccessViolation" runt time error on line. I think it is because, I am trying to allocate unmanaged memory in managed function. But I am not sure how to get around this.
It could be possible that a user name or password are incorrect. AccessViolation is best noted for those issues. Also, I dont see why anything should go wrong the way you are handling things in your code above.
精彩评论