J
James
Greetings,
I have a PowerBasic unmanaged library that I wish to call from C#.
Here's the PB code...
FUNCTION Hello(str AS STRING) EXPORT AS STRING
FUNCTION = "Hello World " & str
END FUNCTION
Simple enough. I can successfully call it from a VB6 component but
can't seem to get the C# syntax right. I've tried the following with
no success. Each time, I get this error at the call to HELLO. Any
ideas?
System.NullReferenceException: Object reference not set to an instance
of an object.
**Attempt 1**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO(string someText);
Console.WriteLine(HELLO("blah"));
**Attempt 2**
[DllImport("Hello.dll", EntryPoint="HELLO", CharSet=CharSet.Auto)]
public static extern string HELLO(ref string someText);
string str = "blah";
Console.WriteLine(HELLO(ref str));
**Attempt 3**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO([MarshalAs(UnmanagedType.LPStr)]
string someText);
Console.WriteLine(HELLO("blah"));
**Attempt 4**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO(StringBuilder someText);
StringBuilder sb = new StringBuilder("blah");
Console.WriteLine(HELLO(sb));
-Cliff
I have a PowerBasic unmanaged library that I wish to call from C#.
Here's the PB code...
FUNCTION Hello(str AS STRING) EXPORT AS STRING
FUNCTION = "Hello World " & str
END FUNCTION
Simple enough. I can successfully call it from a VB6 component but
can't seem to get the C# syntax right. I've tried the following with
no success. Each time, I get this error at the call to HELLO. Any
ideas?
System.NullReferenceException: Object reference not set to an instance
of an object.
**Attempt 1**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO(string someText);
Console.WriteLine(HELLO("blah"));
**Attempt 2**
[DllImport("Hello.dll", EntryPoint="HELLO", CharSet=CharSet.Auto)]
public static extern string HELLO(ref string someText);
string str = "blah";
Console.WriteLine(HELLO(ref str));
**Attempt 3**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO([MarshalAs(UnmanagedType.LPStr)]
string someText);
Console.WriteLine(HELLO("blah"));
**Attempt 4**
[DllImport("Hello.dll", EntryPoint="HELLO")]
public static extern string HELLO(StringBuilder someText);
StringBuilder sb = new StringBuilder("blah");
Console.WriteLine(HELLO(sb));
-Cliff