DllImport and parameters
-
What are the rules for specifying the parameter types for Win API functions using DllImport? E.g. this thing... DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name ); How would I import that? would this be correct... [DllImport("kernel32.dll")] static extern int GetPrivateProfileString(string section, string key, string def, string val, int size, string file);
-
What are the rules for specifying the parameter types for Win API functions using DllImport? E.g. this thing... DWORD GetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name ); How would I import that? would this be correct... [DllImport("kernel32.dll")] static extern int GetPrivateProfileString(string section, string key, string def, string val, int size, string file);
There are two different versions of GetPrivateProfileString, one for ANSI strings and another for wide/Unicode strings; so you'll need to specify that. Your destination buffer should also be a StringBuilder rather than a string. There is a utility posted on GotDotNet that will generate the correct DllImport statements for you. You need a copy of the win32api.txt from VB6 though. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978