Re: how can convert char* to LPTSTR in VS 2005?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



thanks, but i tried this:
__declspec(dllexport) int testFuncString(LPTSTR i, LPTSTR o,int size)
{
int l=0;
char *temp;
temp=malloc(size*sizeof(char));
memset(temp,0,size);

WideCharToMultiByte(CP_ACP,0,i,-1,temp,size,NULL,NULL);
printf("%s\n",temp);

MultiByteToWideChar(CP_ACP,0,temp,-1,o,size);
return 0;

}


i'm trying to call it dotnet 2.0 with this signature:
[DllImport("TestJNI.dll",CharSet=CharSet.Auto)]
static extern int testFuncString(string
i,[Out,MarshalAs(UnmanagedType.LPTStr)] StringBuilder o, int size);

StringBuilder s = new StringBuilder();
s.Length = 10;
string i = "Testing";
testFuncString(i,s,i.Length);


but in the printf i see some gibbirsh after the original string, like i
doesn't stop there.

.



Relevant Pages

  • Re: pinvoke with StringBuilder[] not working for me
    ... public static extern int EnumerateBoards ... I want to pass a pointer to an array of char strings, ... int numBoards, StringBuilder boards); ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... Managed Code in the Embedded World ... I tried StringBuilder it worked, But there is some problem with conversion ... public static extern int myfunc; ... Unmanaged codefunction: int myfunc (char* temp) ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: am having a problem with pinvoke and StringBuilder[ ]
    ... DLL: Hello from TestLib.dll ... Since the String class is immutable, I have used StringBuilder in my code ... public static extern int EnumerateBoards(ref int numBoards, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: am having a problem with pinvoke and StringBuilder[ ]
    ... If you don't have the source of the DLL then you are in a world of pain, that means you wont be able to use the interop marshaler, you need to "custom" marshal. ... public static extern int EnumerateBoards(ref int numBoards, ... Since the String class is immutable, I have used StringBuilder in my code ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Unmanaged code(dll) function: int myfunc (char* temp)
    ... If the native DLL will be putting data into that variable, ... public static extern int myfunc; ... StringBuilder sb = new StringBuilder; ... Unmanaged codefunction: int myfunc (char* temp) ...
    (microsoft.public.dotnet.framework.compactframework)