I have to call an external library that is using some non-standard types, so I've created a C++ wrapper around this external library. To try to save some pain I've setup on of the arguments as a wchar_t*:
void StartBatchJob(wchar_t* server, unsigned short port, int timeout, wchar_t* xml, int length);
When I'm calling the function:
var xml = new StringBuilder("... xml string removed for brevity");
StartBatchJob(((Char*)hostCharPointer), 6015, 60000, ((Char*)Marshal.StringToHGlobalUni(xml.ToString())), xml.ToString().Length);
However, when the function gets called it appears to be cutoff at 256 characters. When I debug/watch the xml parameter in the C++ code I see it's cutoff at 256 characters.
Now, I haven't done any C++ or native code calling in .NET in a very long time, so I have forgotten all the details of it. I don't think it's a problem with the Marshal.StringTo... call as that appears to return a fully rendered char*. It appears it's when the runtime tries to pass the arguments.
Update:
By request, here is the implementation of the StartBatchJob method:
extern "C" ZCHAR * JDEWINAPI jdeXMLRequest(const JCHAR *szHostName, unsigned short usPort, const int nNetTimeout, void *xml, int size);
void JDEService::StartBatchJob(wchar_t* server, unsigned short port, int timeout, wchar_t* xml, int length)
{
ZCHAR* presp = jdeXMLRequest(reinterpret_cast<JCHAR *>(server), port, timeout, xml, length);
}
Any help is greatly appreciated!
Thanks