A
Angel
Hello again (and again, and again...)
I think I'm getting closer to solving my initial problem of calling
unmanaged code. I managed to call the functions with user-defined structs
w/o getting any run-time exceptions. The problem is that I'm receiving a
Failure return (it returns 1 = "Failure"). I have a feeling it may be that
the function's not reading the struct correctly.
This time I decided to display all the code (it's very short). The original
struct declared in the .h looks like this:
typedef struct
{
char detail_code; /* copyright detail code */
char zip_code[5+1]; /* zip code */
char city_key[6+1]; /* city/state key */
} CITY_REC;
The original function syntax is:
int z4ctynxtSTD (CITY_REC *city_rec); //STD for stdcall calling
convention
The struct I converted it to: (in another cs file which only has this
struct):
namespace ZM
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct CITY_REC
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=1)]
public string detail_code;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=6)]
public string zip_code;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=7)]
public string city_key;
}
and the function call i converted to:
[DllImport("C:\\zm7\\Developm\\DLL\\W32.DLL")]
public static extern int z4ctynxtSTD(CITY_REC city); //I used ref but it
didn't work either
public static void getCity()
{
ZIP4_PARM_class zip4 = new ZIP4_PARM_class();
CITY_REC city = new CITY_REC();
int i = z4open();
i = z4ctynxtSTD(city); //I used ref but it didn't work either
MessageBox.Show ("result: " + i.ToString()); // it returns 1, which
is "Failure"
z4close();
}
Am I declaring the struct correctly and am I sending it as parameter
correctly? I'm pretty sure I'm almost done.
Thanks again (and again, and again, and again...
) )
I think I'm getting closer to solving my initial problem of calling
unmanaged code. I managed to call the functions with user-defined structs
w/o getting any run-time exceptions. The problem is that I'm receiving a
Failure return (it returns 1 = "Failure"). I have a feeling it may be that
the function's not reading the struct correctly.
This time I decided to display all the code (it's very short). The original
struct declared in the .h looks like this:
typedef struct
{
char detail_code; /* copyright detail code */
char zip_code[5+1]; /* zip code */
char city_key[6+1]; /* city/state key */
} CITY_REC;
The original function syntax is:
int z4ctynxtSTD (CITY_REC *city_rec); //STD for stdcall calling
convention
The struct I converted it to: (in another cs file which only has this
struct):
namespace ZM
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct CITY_REC
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=1)]
public string detail_code;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=6)]
public string zip_code;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=7)]
public string city_key;
}
and the function call i converted to:
[DllImport("C:\\zm7\\Developm\\DLL\\W32.DLL")]
public static extern int z4ctynxtSTD(CITY_REC city); //I used ref but it
didn't work either
public static void getCity()
{
ZIP4_PARM_class zip4 = new ZIP4_PARM_class();
CITY_REC city = new CITY_REC();
int i = z4open();
i = z4ctynxtSTD(city); //I used ref but it didn't work either
MessageBox.Show ("result: " + i.ToString()); // it returns 1, which
is "Failure"
z4close();
}
Am I declaring the struct correctly and am I sending it as parameter
correctly? I'm pretty sure I'm almost done.
Thanks again (and again, and again, and again...
