Converting MAPI function from VO to X# - PCALL typed function pointer

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am
Location: New Zealand

Converting MAPI function from VO to X# - PCALL typed function pointer

Post by jonhn »

Converting from VO app to X# and have some MAPI email functions that I got from Phil McGuinnes around 2006. I'm not sure whether to rewrite this section using the MS.Outlook.Interop or just fix up the MAPI as it is only used in a couple of methods and Interop for the rest.

Anyway - here's my question, maybe someone has already solved it?

X# error XS9035 The first argument to PCALL must be a "typed function pointer".

Does that mean typing sMAPI.pLogon, or is there a new parameter required?
If typing pLogon, it is declared as a PTR elsewhere - so what is the syntax to type it in PCALL please?

PCALL function is below, and the MAPILogon function below that.

nResult := DWORD( _CAST , PCALL( sMAPI.pLogon , ;
ulUIParam , ;
PSZ( _CAST , lpszName ) , ;
PSZ( _CAST , lpszPassword ) , ;
flFlags , ;
0 , ;
@lphSession ) )


FUNCTION MAPILogon( ulUIParam AS DWORD , ;
lpszName AS PSZ , ;
lpszPassword AS PSZ , ;
flFlags AS DWORD , ;
ulReserved AS DWORD , ;
lphSession REF DWORD ) AS DWORD PASCAL

LOCAL nResult AS DWORD

IF _MAPIInit()
nResult := DWORD( _CAST , PCALL( sMAPI.pLogon , ;
ulUIParam , ;
PSZ( _CAST , lpszName ) , ;
PSZ( _CAST , lpszPassword ) , ;
flFlags , ;
0 , ;
@lphSession ) )
ENDIF
RETURN nResult



While I'm here, Argument 6 may not be passed with the '@' prefix?

IF _MAPIInit()
nResult := DWORD( _CAST , PCALL( sMAPI.pLogon , ;
ulUIParam , ;
PSZ( _CAST , lpszName ) , ;
PSZ( _CAST , lpszPassword ) , ;
flFlags , ;
0 , ;
@lphSession ) )
ENDIF


I have attached all the MAPI function Phil provided as an attachment.

Thank you!
Jonathan
Attachments
MAPIFunctions.txt
(3.62 KiB) Downloaded 82 times
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Converting MAPI function from VO to X# - PCALL typed function pointer

Post by wriedmann »

Hi John,
I don't know if newer releases of the X# runtime support PCall, older versions needed PCallNative.
This is my (cleaned) version of MapiLogon:

Code: Select all

function MAPILogon( ulUIParam as dword , ;
		lpszName as psz , ;
		lpszPassword as psz , ;
		flFlags as dword , ;
		ulReserved as dword , ;
		lphSession ref dword ) as dword pascal

	local nResult := 0 as dword

	if _MAPIInit()
		nResult := PCallNative<dword>( sMAPI.pLogon , ;
					ulUIParam , ;
					lpszName , ;
					lpszPassword , ;
					flFlags , ;
					0 , ;
					@lphSession ) 
	endif

	return nResult
I have added my version of all the MAPI calls here:
MAPI.Functions.zip
(1.99 KiB) Downloaded 83 times
Please beware that this is code that I'm sharing between X# and VO, so I'm using #ifdef statements to keep the compiler happy.
Wolfgang
P.S. MAPI is not supported on 64 bit applications. Microsoft tried to implement it, but failed because it was too badly written in 32 bit. So no MAPI on 64 bit Outlook, you have to use COM/OLE.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am
Location: New Zealand

Converting MAPI function from VO to X# - PCALL typed function pointer

Post by jonhn »

Thank you Wolfgang!
OK, you confirmed my suspicion that it is better to rewrite it now using the Outlook Interop.
Thanks for sharing your cleaned MAPI code - I'll look at that first ;).

Best regards,
Jonathan
User avatar
Chris
Posts: 4898
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Converting MAPI function from VO to X# - PCALL typed function pointer

Post by Chris »

John, Wolfgang,

First of all, I totally agree it's better to use PCallNative() instead of PCALL(), and even better totally replace the code with Interop, as this will make it more modern and make it easier to modify/add more features in the future.

But having said that, PCALL() is still supported in X# (for VO compatibility), it's just that the compiler needs to know the signature of the function to call. This can be done by using an intermediate typed LOCAL like this:

Code: Select all

LOCAL hFuncTyped AS MAPILogon PTR
hFuncTyped := sMAPI.pLogon
	
nResult := DWORD( _CAST , PCALL( hFuncTyped, ... // the rest remains the same
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

Converting MAPI function from VO to X# - PCALL typed function pointer

Post by ArneOrtlinghaus »

Here is our MAPI-Version converted to X#. There is still a small number of users who use this API.
If you need any functions used in this class then you have to ask me.

Arne
Attachments
mapi.txt
(19.46 KiB) Downloaded 78 times
Post Reply