Jump to content

C#


Guest Lan-Kern
 Share

Recommended Posts

Guest Lan-Kern

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?

Link to comment
Share on other sites

Guest Lan-Kern

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);

Link to comment
Share on other sites

  • 5 months later...

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...