G
Guest
Need help porting code.
I have a section of code that is getting an Null exception error
and I want to know if I have ported the function correctly.
The code works in C++ but when running the code in C# I get a
System.NullReferenceException.
Thanks,
C++ Code:
typedef struct _VENDOR_CMD
{
BYTE bRequest;
WORD wValue;
WORD wIndex;
WORD wLength;
BYTE direction;
BYTE bData;
} VENDOR_CMD, *PVENDOR_CMD;
typedef struct _TT_SEND_VENDOR_CMD
{
VENDOR_CMD vcCmd;
DWORD dwDataSize;
PVOID pDataBuf;
} TT_SEND_VENDOR_CMD, *P_SEND_VENDOR_CMD;
BOOL MyClass::myFunction(PVENDOR_CMD pRequest, DWORD dwDataSize, PVOID
pDataBuf)
{
TT_SEND_VENDOR_CMD ttCmd;
memcpy(&ttCmd.vcCmd, pRequest, sizeof(VENDOR_CMD));
ttCmd.dwDataSize = dwDataSize;
ttCmd.pDataBuf = pDataBuf;
return(*pfnIpSysCall)(2, 0, &tjCmd);
} // End myFunction().
C# Code:
struct VENDOR_CMD {
public byte bRequest;
public Int16 wValue;
public Int16 wIndex;
public Int16 wLength;
public byte direction;
public byte bData;
};
struct TT_SEND_VENDOR_CMD {
public VENDOR_CMD vcCmd;
public UInt32 dwDataSize;
public Int32 pDataBuf;
} ;
private bool myfuunction(VENDOR_CMD pRequest, UInt32 dwDataSize, ref byte
pDataBuf) {
bool returnCode = false;
TT_SEND_VENDOR_CMD ttCmd;
ttCmd.vcCmd = pRequest;
ttCmd.dwDataSize = dwDataSize;
ttCmd.pDataBuf = pDataBuf;
//
// Exception Here when calling function:
//
// An unhandled exception of type 'System.NullReferenceException' occurred
in tttest.exe
//
// Additional information: Object reference not set to an instance of an
object
//
returnCode = IpSysCall(2, 0, ref ttCmd);
return(returnCode);
} // End myfunction().
I have a section of code that is getting an Null exception error
and I want to know if I have ported the function correctly.
The code works in C++ but when running the code in C# I get a
System.NullReferenceException.
Thanks,
C++ Code:
typedef struct _VENDOR_CMD
{
BYTE bRequest;
WORD wValue;
WORD wIndex;
WORD wLength;
BYTE direction;
BYTE bData;
} VENDOR_CMD, *PVENDOR_CMD;
typedef struct _TT_SEND_VENDOR_CMD
{
VENDOR_CMD vcCmd;
DWORD dwDataSize;
PVOID pDataBuf;
} TT_SEND_VENDOR_CMD, *P_SEND_VENDOR_CMD;
BOOL MyClass::myFunction(PVENDOR_CMD pRequest, DWORD dwDataSize, PVOID
pDataBuf)
{
TT_SEND_VENDOR_CMD ttCmd;
memcpy(&ttCmd.vcCmd, pRequest, sizeof(VENDOR_CMD));
ttCmd.dwDataSize = dwDataSize;
ttCmd.pDataBuf = pDataBuf;
return(*pfnIpSysCall)(2, 0, &tjCmd);
} // End myFunction().
C# Code:
struct VENDOR_CMD {
public byte bRequest;
public Int16 wValue;
public Int16 wIndex;
public Int16 wLength;
public byte direction;
public byte bData;
};
struct TT_SEND_VENDOR_CMD {
public VENDOR_CMD vcCmd;
public UInt32 dwDataSize;
public Int32 pDataBuf;
} ;
private bool myfuunction(VENDOR_CMD pRequest, UInt32 dwDataSize, ref byte
pDataBuf) {
bool returnCode = false;
TT_SEND_VENDOR_CMD ttCmd;
ttCmd.vcCmd = pRequest;
ttCmd.dwDataSize = dwDataSize;
ttCmd.pDataBuf = pDataBuf;
//
// Exception Here when calling function:
//
// An unhandled exception of type 'System.NullReferenceException' occurred
in tttest.exe
//
// Additional information: Object reference not set to an instance of an
object
//
returnCode = IpSysCall(2, 0, ref ttCmd);
return(returnCode);
} // End myfunction().