Two diffrences
1. I did not declare the dll methods extern
2. I did not have this statement in the methods
__declspec( dllexport
I will add them and see what happens
Thanks for the posts
----- mikeb wrote: ----
Honus wrote
Howdy
The C# method is calling via the [DllImport] syntax
[DllImport "theDll.dll"
public static extern bool theMethod(int i)
I assume this is a typo - if you're passing on 0x02 to 'theMethod()',
then the result of (x&y) is true, not false
I wrote a small test DLL and C# console app to test this, and got no
surprises
====== test.pinvoke.cs ================================
using System
using System.Runtime.InteropServices
public class TestPInvoke
[DllImport( "theDll.dll")
public static extern bool theMethod( int i)
[DllImport( "theDll.dll")
public static extern bool theMethod2( int i)
public static void Main()
int y = 0x01
Console.WriteLine( @"Calling ""theMethod( y)""")
bool res1 = theMethod( y)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine( @"Calling ""theMethod2( y)""")
bool res2 = theMethod2( y)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine( "theMethod( y) returned {0}", res1)
Console.WriteLine( "theMethod2( y) returned {0}", res2)
int z = 0x02
Console.WriteLine( @"Calling ""theMethod( z)""")
res1 = theMethod( z)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine( @"Calling ""theMethod2( z)""")
res2 = theMethod2( z)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine( "theMethod( z) returned {0}", res1)
Console.WriteLine( "theMethod2( z) returned {0}", res2)
return
=========================================================
====== theDll.cpp =======================================
#include <stdio.h
extern "C"
__declspec( dllexport
bool theMethod(unsigned int x
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
return true
els
return false
__declspec( dllexport
bool theMethod2(unsigned int x
unsigned int y = 0x2
if (x&y) // FALSE
printf("True")
if (x&y
printf("")
return true
els
return false
=========================================================
I compiled these with the following commands
csc /t:exe test.pinvoke.c
cl /LD /MD thedll.cp
And ran "test.pinvoke.exe" with the expected results
What's different between this code and your code