C # encountered by C ++ written COM problems and solutions

xiaoxiao2021-03-19  183

problem:

The interface defined in C is as follows:

// ...

[Propget, ID (0), Helpstring ("Get User Nickname")] HRESULT NICKNAME ([OUT, RETVAL] BSTR * PVAL); [PropPut, ID (1), Helpstring ("Set User Nickname")] HRESULT NICKNAME BSTR newVal;

// ...

C # in COM Interop call, obtain the user nickname return error "Not set the object reference to the object instance", set the user nickname normal

Problem reason (not necessarily, you can solve the problem):

No memory is allocated to * PVAL when "getting user nickname"

Solution:

"[PropGet, ID (0), Helpstring (" Get User Nickname ")] HRESULT NICKNAME ([OUT, RETVAL] BSTR * PVAL);" Modified to:

[ID (0), Helpstring ("Get User Nickname")] HRESULT GETNICKNAME ([IN, OUT] BSTR * PVAL);

The intero package is called after the package:

// .....

String nickname = new string (new char [25]); // User nickname length is 25

User.getnickname (REF NICKNAME); // User For this purposeful object, Nickname is the user nickname value

// .....

===========================

The solution is not necessarily good. If you have a better solution, please leave a message, everyone discusses

转载请注明原文地址:https://www.9cbs.com/read-130227.html

New Post(0)