could you show us your code atleast so that others can get idea.
thanx
Paresh
Printable View
could you show us your code atleast so that others can get idea.
thanx
Paresh
Yep, it's pretty straightforward when you know how.
Here's the C# method:
public unsafe void GetString( sbyte* String )
{
string TestString = "Hello World";
// Convert string to unsafe pointer
char[] CharArray = new char[TestString.Length];
CharArray = TestString.ToCharArray();
foreach ( char Char in CharArray )
{
*String++ = (sbyte)Char;
}
// Add terminating null
*String = (sbyte)'\0';
}
and the C/C++ code to call it:
char String[30];
GetString( String );
Hope that helps (obviously need to check for string overflow)
Sarah ;)
thanks...;)
Hi guys,
Interesting thread. I have same problem, but I have exported function which I cannot change. The declaration is:
short MyFunc(TCHAR* cRefNumber);
and the export is defined in the *.def file.
And your advice does not work with this scenario. I got the error below on the line MyString = Marshal.PtrToStringUni(ptr);
“An unhandled exception of type ‘System.NullReferenceException’ occurred in mscorlib.dll”.
:confused:
Could you help me, please?
Btw: I am new in .NET and C#.
Thanks,
David
to me it looks like you haven't initialized the string.
paresh
I initialized the string.
I think the main difference is between declartions of exported function. GMV’s solution contains two pointers, but I have only one:
GetStringFromDLL(WCHAR** ppString);
MyDLLFunc(TCHAR* pszRefNumber);
But I cannot change it.
thanks anyway,
David
Hello Experts,
I also have some problems related to string ...
Sorry for posting this question again ...
I want to use a function written in C++ VS6.0 dll.
The function takes "CString&" as an argument.
I want to call this function from a Managed C++ dll.
// .....
CString strTest;
CString strTest1;
SomeFnInVC6( strTest );
strTest1 = strTest; // ----->>> Exception here !!!
// ....
Is it possible to do like this ? Please give me a solution.
Thanks.