This message was discovered on microsoft.public.dotnet.framework.interop.
| Thomas Fisher |
Hello,
This is a rephrasing of a previous question that I didn't get an answer to, maybe putting it differently will help.
In Baf.dll there is a function prototype:
BOOL CDECL LaunchRunner (LPCSTR szUserDisplay, BOOL* pbEnabled);
How would this be defined in VB.Net or C# and how should I call it? I've tried everything I can think of and am getting null reference errors. I posted code in the previous post (on 8/6).
Thanks a lot for any help with this...
- Tom
|
|
| |
| |
| BMermuys |
Hi,
"Thomas Fisher" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
<DllImport("...", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi) > _ Public Function LaunchRunner( _ ByVal szUserDisplay As String, _ ByRef pbEnabled As Boolean) As Boolean End Function
If it doesn't work then maybe your c sign isn't right, the function doesnt work properly or BOOL is different then the one in wtypes.h
HTH, greetings
[Original message clipped]
|
|
| |
| |
| Thomas Fisher |
Ok,
Here's an update of the code I'm using, still not working.
C++ Prototype from Baf.dll: BOOL CDECL LaunchRunner (LPCSTR szUserDisplay, BOOL* pbEnabled);
C# Wrapper: [DllImport("Baf.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] public static extern bool LaunchRunner ( string szUserDisplay, [MarshalAs(UnmanagedType.Bool)] ref bool pbEnabled ); //note: I've also tried marshaling it is VariantBool and U1
VB.Net Call to C# Wrapper: Dim buffer As String = "AB" buffer.PadRight(255, vbNullChar) Dim handle As GCHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned) Dim sPtr As IntPtr = handle.AddrOfPinnedObject
Dim B As Boolean = True Dim bPtr As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(B.GetType)) Marshal.StructureToPtr(B, bPtr, False)
If Not LaunchRunner (buffer, B) Then Throw New Exception("LaunchRunner failed") End If
Marshal.FreeCoTaskMem(bPtr) handle.Free()
The function is returning false (no error) so something's not right but I think I'm getting closer. It would be great if someone who knows more than me could take a look at this and tell me what's wrong.
Thanks!
|
|
| |
| |
| Robert Jordan |
Hi Thomas,
[Original message clipped]
You don't need to manually marshal the string:
[DllImport("Baf.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool LaunchRunner( [MarshalAs(UnmanagedType.LPStr)] string szUserDisplay, [MarshalAs(UnmanagedType.Bool)] ref bool pbEnabled );
bye Rob
|
|
| |
| |
| Thomas Fisher |
Thanks for the help.
[Original message clipped]
I've changed the wrapper to match this and have tried calling it in several ways and none work. An example call:
LaunchRunner("AB", True)
Any more ideas?
|
|
| |
| |
| Robert Jordan |
Hi Thomas,
[Original message clipped]
There are 2 kinds of unmanaged bools:
1 byte C++/C 4 bytes (WINAPI)
You may try whether the 1 byte version applies using [MarshalAs(UnmanagedType.I1)] for both bools.
bye ROb
|
|
| |
| |
| Thomas Fisher |
[Original message clipped]
Here's the definition from the header file: BOOL CDECL LaunchRunner( LPCSTR szUserDisplay , BOOL* pbEnabled ); typedef BOOL (CDECL* fLaunchRunner)( LPCSTR szUserDisplay , BOOL* pbEnabled );
I've tried it with I1 for both and still no go. I've been trying every permutation i can think of...any other ideas?
|
|
| |
|
|
|
|
|
| |
| Thomas Fisher |
> <DllImport("...", CallingConvention:=CallingConvention.Cdecl, CharSet:=CharSet.Ansi) > _ > Public Function LaunchRunner( ByVal szUserDisplay As String, ByRef pbEnabled As Boolean) As Boolean > End Function
[Original message clipped]
Thanks for the reply! Ok, I've tried this and it still didn't work. - by "c sign" are you referring to the declaration? If so, I'm sure it's right. - the function does work properly, i know because there is a control panel that calls this function - how would i know what type of bool to use? what others are there to try?
Thanks for the help...
|
|
| |
| |
| BMermuys |
Hi,
"Thomas Fisher" <thesequoyan [[[a]]] hotmail> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
Do you have some code in any language that uses the function which works ?
[Original message clipped]
Well, the sign or declaration does it come from a header file ? If so, check the header file if it defines or typedefs BOOL or if it includes any other header which does so.
Something must be wrong, because I have a function with the same sign which works without any problems.
Why do you allocate 255 chars for the string, does the function wants a fixed size string ? The function doesnt alter the string does it ?
HTH, greetings
[Original message clipped]
|
|
| |
| |
| Thomas Fisher |
[Original message clipped]
Here's the definition from the header file: BOOL CDECL LaunchRunner( LPCSTR szUserDisplay , BOOL* pbEnabled ); typedef BOOL (CDECL* fLaunchRunner)( LPCSTR szUserDisplay , BOOL* pbEnabled );
> Something must be wrong, because I have a function with the same sign which > works without any problems.
How do you call it? With a System.String and System.Boolean? Do you pin them first?
[Original message clipped]
Because of what I read in this thread: http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/205640_Thread.aspx
|
|
| |
|
|
|
|
|
|
|
|