Click here to Skip to main content
15,891,903 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
I am calling a C++ dll from C#. The method that I call receives a string parameter. When I call with a string without special characters there's no problem but when I call with a string that has characters like 'é' 'è' 'ç' 'à' and also like '(' I get a crash. No errors ... just that it doesn't get back from the call ... it hangs there.

In the call I pass a pointer to the string as parameter. The Import looks like this
C#
[DllImport("gsdll64.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv);



Suggestions?
Posted
Updated 17-Dec-13 2:18am
v3
Comments
Pablo Aliskevicius 17-Dec-13 8:13am    
Which of your parameters is a string?
What is the C++ function signature?
chandanadhikari 17-Dec-13 8:57am    
Maybe something is wrong in the way you are handling strings. For strings with special characters only wide character string types should be used and proper care needs to be taken while allocating and deallocating memory . Run in debug mode and see at which line specifically the crash is happening and check if the string variables/pointers are still holding proper data or are they corrupted.
Maciej Los 17-Dec-13 9:15am    
Are you an author of dll?
Christopher Drake 19-Dec-13 11:33am    
Is it expecting an array of single byte characters?

1 solution

You can try to declare the function as
C#
[DllImport("gsdll64.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int InitAPI(IntPtr instance, int argc, string[] argv);

See the link to GhostScript64.cs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900