Hi, i am trying to call A dll FUNCTION from a C# application.
i am using this function
int hhpGetErrorMessage(PTCHAR ptcErrorMsg,int nMaxChars)
where
ptcErrMsg: TCHAR buffer to hold error message string.
nMaxChars: Maximum number of characters that can fit in ptcErrorMsg
including NULL.
i defined this function in C# as
// Miscellaneous Error Code Message function.
[DllImport("hhpImgrSdk.dll", CharSet=CharSet.Auto)]
public static extern int hhpGetErrorMessage(string ptcErrorMsg,int
nMaxChars );
i call this function as
string s();
hhpGetErrorMessage(s,128);
i get an error message " Use of unassigned local variable 's'"
when i declare s as string s =new string (' ',128);
it seems to pass the error msg, but the result i get from s is junk
a junk value such as "œ—ž¾'Ì•Š"¬ œäûr"
i know ptcErrorMsg will hold the error msg returned by
hhpGetErrorMessage()
when i tried to change my function to accept a ref to a string such as
[DllImport("hhpImgrSdk.dll", CharSet=CharSet.Auto)]
public static extern int hhpGetErrorMessage(ref string ptcErrorMsg,int
nMaxChars );
i got an Exception "An unhandled exception of type
'System.ExecutionEngineException'"
i dont know for sure if its a Marshaling problem?
i know that PTCHAR,TCHAR* can be substituted in C# by string..
i cannot change the DLL !!
how do i declare a string of a certain size without an initial value
any idea?
thanks all
Mo
ma******@hotmail.com