Re: NullReferenceException when passing structures by reference to a C API

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,

i think you don't have to issue
> ADMIN_PROF admin_prof = new ADMIN_PROF();

cause Marshal.PtrTo.. will return a new object, so you're effectivly
overwriting the one you've created with "new"

to isolate the problem you may comment out some members of ADMIN_PROF struct
e.g.

[StructLayout(LayoutKind.Sequential)]
public struct ADMIN_PROF
{
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=NAME_LEN )]
public String login_name;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=ORG_NAME_LEN )]
public String org_name;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=NAME_LEN )]
public String printer;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=NAME_LEN )]
public String business_unit;
public int warning_flag;
public int create_admin;
public int create_infra;
public int create_dns_rrs;
// [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=20 )]
// public String max_gui_level;
// public CONTACT_LST personrec;
// public IntPtr access_lst;
}

then run the code, if it succeeds remove one comment and run again, and
repeat this until the error comes up again ..
then you'll know what member causes the Net marshaler to fail and we can
continue trying to find a working solution ..

Regards
Christian


.



Relevant Pages