[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Issue 1628

From: Jonathan Gilbert <o2w9gs702_at_sneakemail.com>
Date: 2005-07-24 17:44:38 CEST

At 02:56 PM 24/07/2005 +0200, =?UTF-8?B?QnJhbmtvIMSMaWJlag==?=
brane-at-xbc.nu |subversion de wrote:
>SteveKing wrote:
>>+typedef LPVOID (*InstallEx)(LPGETLOGFILE pfn, LPCSTR lpcszTo, LPCSTR
lpcszSubject);
>>+typedef void (*UninstallEx)(LPVOID lpState);
>>+HMODULE crashDll = 0;
>>+LPVOID lpvState = 0;
>>+svn_cmdline_remove_crashrpt()
>>+{
>>+ UninstallEx pfnUninstallEx;
>>+ if ((crashDll)&&(lpvState))
>>+ {
>>+ pfnUninstallEx = (UninstallEx)GetProcAddress(crashDll, "UninstallEx");
>>+ (UninstallEx)(lpvState);
>>+ }
>>+ FreeLibrary(crashDll);
>>+}
>>+#endif

There is another problem with this: It is not actually calling the
UninstallEx function. The address is put into a variable called
"pfnUninstallEx", but then instead of calling through that variable, Stefan
is for some reason casting lpvState to the function pointer type. Oops :-)

In general, you do not need extra brackets or a dereference when calling
through a function pointer. If this had been written as:

   UninstallEx(lpvState);

..then it would have failed to compile, notifying you of the error.
Hungarian notation aside, the line should of course read:

   pfnUninstallEx(lpvState);

Another possible issue is that the functions from the DLL are almost
certainly using the stdcall calling convention, and you are not specifying
this calling convention in your typedefs. It is done like this:

typedef LPVOID (__stdcall * InstallEx)(LPGETLOGFILE pfn, LPCSTR lpcszTo,
LPCSTR lpcszSubject);
typedef void (__stdcall * UninstallEx)(LPVOID lpState);

If you don't like the look of this compiler-specific token, you can use the
standard Windows macro "WINAPI" in its place:

typedef LPVOID (WINAPI * InstallEx)(LPGETLOGFILE pfn, LPCSTR lpcszTo,
LPCSTR lpcszSubject);
typedef void (WINAPI * UninstallEx)(LPVOID lpState);

This is marginally more portable too, since the Win32 context on Macs (now
defunct, afaik, so really a moot point) uses CDECL, and, more to the point,
older Visual C++ compilers didn't know the __stdcall directive. The header
file "WinDef.h" in the platform SDK takes care of all this through the
WINAPI macro. :-)

Jonathan Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Jul 24 17:49:49 2005

This is an archived mail posted to the Subversion Dev mailing list.