c# - How to update some COM marshalling code to work on a 64 bit system? -



c# - How to update some COM marshalling code to work on a 64 bit system? -

we have .net code phone call out com component (dnsapi.dll) query whether domain has mx records associated validate email addresses entered our site.

the problem we've upgrading 32 bit systems 64 bit systems , code marshals between com types , .net types (and cleans after) doesn't work more.

the com phone call puts results in memory , returns pointer are. code marshals results .net struct still works fine code cleans memory after corrupts heap , crashes iis app pool.

it's 64/32 bit problem because created little console app calls same code , works fine when compile 32 bit displays same heap corruption behavior when compile 64 bit.

i found stackoverflow post of having same problem , said solution was:

the solution seek create sure win32 struct , c# struct bit(bit size) mapping. can achieved using exact c# type win32 type.

i've not done much interop before , not sure needs change. here's msdn documentation says native construction looks like:

typedef struct _dnsrecord { dns_record *pnext; pwstr pname; word wtype; word wdatalength; union { dword dw; dns_record_flags s; } flags; dword dwttl; dword dwreserved; union { dns_a_data a; dns_soa_data soa, soa; dns_ptr_data ptr, ptr, ns, ns, cname, cname, dname, dname, mb, mb, md, md, mf, mf, mg, mg, mr, mr; dns_minfo_data minfo, minfo, rp, rp; dns_mx_data mx, mx, afsdb, afsdb, rt, rt; dns_txt_data hinfo, hinfo, isdn, isdn, txt, txt, x25; dns_null_data null; dns_wks_data wks, wks; dns_aaaa_data aaaa; dns_key_data key, key; dns_sig_data sig, sig; dns_atma_data atma, atma; dns_nxt_data nxt, nxt; dns_srv_data srv, srv; dns_naptr_data naptr, naptr; dns_opt_data opt, opt; dns_ds_data ds, ds; dns_rrsig_data rrsig, rrsig; dns_nsec_data nsec, nsec; dns_dnskey_data dnskey, dnskey; dns_tkey_data tkey, tkey; dns_tsig_data tsig, tsig; dns_wins_data wins, wins; dns_winsr_data winsr, winsr, nbstat, nbstat; dns_dhcid_data dhcid; } data; } dns_record, *pdns_record;

here's our .net struct:

[structlayout(layoutkind.sequential)] private struct dnsrecord { public intptr pnext; public string pname; public int16 wtype; public int16 wdatalength; public int32 dwflags; public int32 dwttl; public int32 dwreserved; public intptr pnameexchange; public int16 wpreference; public int16 pad; }

i know intptr different size depending on whether app running 64 bit or 32 bit doesn't seem can control. i'm not sure whether need create fields bigger or smaller. ideally i'd understand what's going on , why problem.

i know alternative utilize 3rd party library purely through clr code. unfortunately .net1.1 library hard upgrade right can't plug in .net library. i've had .net library can query mx records , require newer version of .net.

yes, construction far short, didn't handle info field correctly. construction needs 64 bytes in 32-bit mode, 88 bytes in 64-bit mode. memory getting corrupted in 32-bit version of iis well, haven't noticed it.

use marshal.sizeof(typeof(dnsrecord)) verify. required sizes adding these fields structure:

[structlayout(layoutkind.sequential)] struct dnsrecord { public intptr pnext; // etc.. public int16 pad; private int pad1; private int pad2; private int pad3; private int pad4; private int pad5; private intptr pad6; private intptr pad7; private intptr pad8; }

c# .net interop 64bit com-interop

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -