开发者

Is it possible to pass an std::string via Microsoft RPC?

开发者 https://www.devze.com 2023-02-15 00:04 出处:网络
I tried passing an std::string via RPC, but I got the following error: MIDL2025: syntax error: expecting a

I tried passing an std::string via RPC, but I got the following error:

MIDL2025: syntax error: expecting a type specification or a storage specifer or a type qualifier near 开发者_开发知识库"string"

Extract from code:

interface TestInterface
{
    unsigned int HelloUser([in] const string user);
}

Is this possible?


You must use a BSTR. Also, no const. By specifying the argument as [in], it is already understood that the callee will not modify the string, and even if it did modify, it won't be marshaled back to the caller.

The _bstr_t class will help with conversion. Note that BSTR is always based on WCHAR, which is 16-bit. Thus, use std::wstring.

0

精彩评论

暂无评论...
验证码 换一张
取 消