简体   繁体   中英

Can I call MAPI32.DLL > MAPISendMail from a 64-bit C# Winforms application?

I have converted a 32-bit WinForms application to 64-bit, but am unsure about what to with a call to MAPI32.DLL > MAPISendMail? I didn't think you could call a 32-bit dll directly from a 64-bit one, but thought I would see what happens. Curiously, it seems to work, but I don't know if it is safe.

The DLL is called as follows:

[DllImport("MAPI32.DLL")]
public static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flg, int rsv);

//...fill in message

// Call the API
int error = Mapi32.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, Mapi32.MAPI_DIALOG, 0);

Is it safe to do this from a 64-bit WinForms app, or am I just lucky it doesn't crash?

Yes, it is safe. An appropriate library will be used and loaded (mapi32.dll) from the appropriate system directory:

  • x64 or x86 natively
%windir%\system32\mapi32.dll
  • x86 on WoW mode
%windir%\syswow64\mapi32.dll

You can read more about that in the Building MAPI applications on 32-bit and 64-bit platforms article.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM