My question is a little general, so I'm not looking for an exact answer, but maybe some guidelines that will help with this will help me ...
At my workplace, I program mainly in C #. We have this third-party company we work with, which gave us the Native C ++ dll that we should use. Since the C ++ method I needed was not disclosed in a way that it was easy to reference C #, I wrapped the dll in another Native C ++ Dll.
So now I have 2 Native C ++ dlls, one of which wraps the other.
I created a small C # console application that calls a method that I created in C ++. My method signature is as follows:
[DllImport("HashMethodWrapper.dll")] [return: MarshalAs(UnmanagedType.LPStr)] private static extern string CreateHash( string input, [MarshalAs(UnmanagedType.LPStr)]StringBuilder output);
In my console application, everything works fine, and I always get the im string waiting for the result.
But when I go to the web service or the created web application (since this is exactly what I really need), I see that getting the string im is garbage and not even consistent. It seems that I get only some reference to the memory that is lost or something like that, but this is just my guess ...
I do not know why this is happening, since everything works fine in my console application.
Does anyone have a direction that could help me? ...
Thanks in advance, gillyb
Edit: I thought this might be due to some loose objects, so I tried calling the method in a fixed expression, for example:
unsafe public static string CreateHashWrap(string pass) { String bb; StringBuilder outPass = new StringBuilder(); fixed (char* resultStr = CreateHash(pass, outPass)) { bb = new String(resultStr); } return bb; }
... but it still did not do this for me. Is it right to link objects?
2nd Edit: The method signature in C ++ looks like this:
extern "C" __declspec(dllexport) char *CreateRsaHash(char *inputPass, char *hashPass);
3rd Edit: I replaced the method signature
extern "C" __declspec(dllexport) bool CreateRsaHash(char *inputPass, char *hashPass);
and im looks for the return value in the *hashPass parameter.
Now I have created a simple console application to test it. When you insert DllImport into my main class and directly call the method, everything works fine, but when I move DllImport and wrap the method in another class and call this class from the "Main" Console method, I get a StackOverflow exception!
Anyone have any idea why this is happening?