xsharp.eu • Converting MAPI function from VO to X# - PCALL typed function pointer
Page 1 of 1

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

Posted: Wed Sep 28, 2022 8:43 pm
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

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

Posted: Thu Sep 29, 2022 3:17 am
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 82 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.

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

Posted: Thu Sep 29, 2022 3:26 am
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

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

Posted: Thu Sep 29, 2022 8:25 am
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

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

Posted: Fri Sep 30, 2022 12:50 pm
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