Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a C# project that uses an dll function, via import, where the dll is created from an unmanaged c++ project.

[DllImport("sample.dll")]
int readPath(string somePath);


On the C++ side, the function definition is:
int readPath(wchar_t* somePath);


When I try to call the function from C# side and pass in Application.StartupPath... The following DOES NOT WORK!
readPath(Application.StartupPath);

On the C++ side I end up getting only the first CHAR of the path.

But by calling ToString(), I get the entire path string just fine.
readPath(Application.StartupPath.ToString());


Can someone explain why that's the case?

Thanks!
Posted
Updated 3-Jun-11 14:46pm
v2

1 solution

I am not familiar with c++ and I am absolutely not sure, but I think it is caused by the wchar_t type.

I think you are trying to read a unicode string into an ANSI character string. Since byte 0 is a string-terminator Application.StartupPath is empty.

Appearantly ToString() converts the unicode string to a normal string.
 
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