I am getting exception on my C# dll call for
[DllExport(CallingConvention = CallingConvention.Cdecl)]
public static int SetSiteInterface(IntPtr siteInterfacePtr)
{
try
{
gSite = (SiteInterface)Marshal.PtrToStructure(siteInterfacePtr, typeof(SiteInterface));
}
catch(Exception ex)
{
}
return 1;
}
as PInvoke restriction: cannot return variants. PtrToStructure is not working.
gSite is SiteInterface as follows:
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct SiteInterface
{
public int nStructSize;
public delegate int GetArraySizeDelegate();
public GetArraySizeDelegate GetArraySize;
public delegate float GetStockArrayDelegate(int nType);
public GetStockArrayDelegate GetStockArray;
public delegate AmiVar GetVariableDelegate(string pszName);
public GetVariableDelegate GetVariable;
public delegate void SetVariableDelegate(string pszName, AmiVar newValue);
public SetVariableDelegate SetVariable;
public delegate AmiVar CallFunctionDelegate(string szName, int nNumArgs, AmiVar ArgsTable);
public CallFunctionDelegate CallFunction;
public delegate AmiVar AllocArrayResultDelegate();
public AllocArrayResultDelegate AllocArrayResult;
public delegate object AllocDelegate(uint nSize);
public AllocDelegate Alloc;
public delegate void FreeDelegate(object pMemory);
public FreeDelegate Free;
public delegate int GetDateTimeArrayDelegate();
public GetDateTimeArrayDelegate GetDateTimeArray;
}
The above site interface C# code was converted from C++ code as shown below:
struct SiteInterface
{
int nStructSize;
int (*GetArraySize) (void);
float * (*GetStockArray)( int nType );
AmiVar (*GetVariable) ( const char *pszName );
void (*SetVariable) ( const char *pszName, AmiVar newValue );
AmiVar (*CallFunction) ( const char *szName, int nNumArgs, AmiVar *ArgsTable );
AmiVar (*AllocArrayResult) (void);
void * (*Alloc) (unsigned int nSize);
void (*Free) (void *pMemory);
DATE_TIME_INT* (*GetDateTimeArray) (void); };
PLUGINAPI int SetSiteInterface( struct SiteInterface *pInterface )
{
gSite = *pInterface;
return TRUE;
}
What am I doing wrong here? Please let me know if you have answer.