Guest Lan-Kern Posted April 8, 2005 Posted April 8, 2005 Ok I am trying to get this to work from within C#. Here is the code I have:[DllImport ("AutoItX3.Dll", EntryPoint="AU3_WinGetText")]public static extern void WinGetText(string title, string text, ref string returnTxt, int buff);and when i call it like this and pass in ref temp as the 3rd parameter it always comes back unchanged.Any Ideas?
Guest Lan-Kern Posted April 8, 2005 Posted April 8, 2005 Ok I am trying to get this to work from within C#. Here is the code I have:[DllImport ("AutoItX3.Dll", EntryPoint="AU3_WinGetText")]public static extern void WinGetText(string title, string text, ref string returnTxt, int buff);and when i call it like this and pass in ref temp as the 3rd parameter it always comes back unchanged.Any Ideas?<{POST_SNAPBACK}>It seems like C# is having trouble converting from char* to string. . if you use byte[] as the param it works fine.[DllImport ("AutoItX3.Dll", EntryPoint="AU3_WinGetText")]public static extern void WinGetText(string title, string text, byte[] returnTxt, int buff);
illumin Posted September 21, 2005 Posted September 21, 2005 It seems like C# is having trouble converting from char* to string. . if you use byte[] as the param it works fine.[DllImport ("AutoItX3.Dll", EntryPoint="AU3_WinGetText")]public static extern void WinGetText(string title, string text, byte[] returnTxt, int buff);You can also use an InPtr type. This is right out of MSDN:Note Win32 API functions that allocate a string enable you to free the string by using a method such as LocalFree. Platform invoke handles such parameters differently. For platform invoke calls, make the parameter an IntPtr type instead of a String type. Use methods provided by the System.Runtime.InteropServices.Marshal class to convert the type to a string manually and free it manually.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now