Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DocumentProperties anyone?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01010251
Message ID:
01011539
Views:
12
>>No, the third parameters is pointer to PRINTER_INFO_x structure where in that structure lies the pointer to DEVMODE structure.
>>
>>You see this code from the example at the above link:
>>
>>pi2->pDevMode = pDevMode
>>
>
>Okay, but the point is that VFP doesn't handle pointers very well. I'm still not sure what to put in the third parameter.
>

You are right. If you pass the POINTER as a STRING @ (from VFP), some (or many ???) of API functions doesn't work well, especially when you deal with an environment that is out of VFP application environment. It can even crash VFP. But if you pass a TRUE POINTER from VFP, it will work very fine. Using this techniques, VFP never failed on me. Passing a STRING @ from VFP is only for the sake of simplicity :)


>>
>>It is not SendMessage() though. It's SendMessageTimeout:
>>
>>SendMessageTimeout(HWND_BROADCAST, WM_DEVMODECHANGE, 0L,
>>   (LPARAM)(LPCSTR)pPrinterName, SMTO_NORMAL, 1000, NULL);
>>
>
>Hmmm... looks like that 4th parameter is a pointer again. That's what's really causing me problems. Maybe I'm better off sticking to figuring out what's wrong with my DocumentProperties command!

You can use STRING @ in VFP:
Declare Long SendMessageTimeout in User32 ;
   Long nhWnd, Long nMessage, Long wParam, String @lParam, ;
   Long nFlags, Long nTimeout, Long @dwResult
SendMessageTimeout( HWND_BROADCAST, WM_DEVMODECHANGE, 0, ;
   cPrinterName, SMTO_NORMAL, 1000, 0 )
Well, I think pointer is confusing to some VFP'er who knows a bit (or never use) a Low Level Language. Let's make it straight. The important thing is, from VFP POV, assume a pointer is just a NUMBER, that's it (that's all !!) don't get confuse. So you can use Integer or Long to pass in a parameter.

Examine this C/C++ from MSDN example code. I have thrown out some checking code so you can see it clearer:
bFlag = GetPrinter(hPrinter, 2, 0, 0, &dwNeeded);
pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded);

// The second GetPrinter fills in all the current settings, so all you
// need to do is modify what you're interested in...
bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
You can convert it to VFP this way:
#Define  GPTR  0x40

*** Since VFP also has internal GetPrinter() function,
***    we need to change this API name to differentiate.
Declare Long GetPrinter in WinSpool.Drv as API_GetPrinter ;
   Long hPrinter, Long nLevel, Long pPrnInfo, ;
   Long nBufSize, Long @nBufNeeded

Declare Long GlobalAlloc in Kernel32 Long uFlags, Long dwBytes

dwNeeded = 0
bFlag = API_GetPrinter( hPrinter, 2, 0, 0, @dwNeeded )

** the return value is just a NUMBER. Or you can say... a POINTER :)
pi2 = GlobalAlloc( GPTR, dwNeeded )
bFlag = API_GetPrinter( hPrinter, 2, pi2, dwNeeded, @dwNeeded )
You see, it is very easy to use a Pointer in VFP :-)
BTW, since Christian already made an FLL, why not give it a try. Hope it can make your problems disappear.

Regards & good luck
Herman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform