I am trying to write a wrapper in C# for an unmanaged C/C++ dll I need to work with. In the process I am tring to kick the rust off of my very old C++ skills. In the .h file I see the code below.
png_demand_record_create(const char *name, const char* loc, int date, int quantity);
The first two parameters are srings and the second two are integers….right? I seem to remember in c there really is not a string but an array of characters, or the like. Isn’t *name the pointer to the character array? Why in the second parameter is the * after the “r” in char and not before the “l’ in loc??? Waht is the difference between those two parameters? Could it just by the typing of the author and it really does not matter?
Also, I am using a tool (Pinvoker) to help me write the C# wrapper for the call to the unmanaged dll (all I have is the .h file and the compiled dll). The tool gives me the following:
[DllImport(@"C:\Some.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public extern static png_demand_record_t png_demand_record_create([MarshalAs UnmanagedType.LPStr)] string name,
[MarshalAs(UnmanagedType.LPStr)] string loc,
int date,
int quantity);
Looks to me as if the tool defines “name” and “loc” the same even though they are different in the .h file. Do I need to worry about this?
Thanks a ton!
To answer your first question: They are exactly the same.
char* stris the same aschar *stris the same aschar*stris the same aschar * str, etc.As for the C#, I’m afraid I can’t be of much help there.
If you’re interested, or if it’s relevent, here‘s the wikipedia page on c-strings (which is what you’re dealing with here).