Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C Structure query
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00612717
Message ID:
00613840
Views:
36
This message has been marked as a message which has helped to the initial question of the thread.
>> Next, you can allocate memory for string using WinAPI function GlobalAlloc (or something similar), get a pointer to memory with GlobalLock, copy string to buffer and store pointer value in structure. After call of function you have to free the memory by GlobalFree.
>
>I see what you mean... I'll try it out. Thanks.

Here a sample for MessageBoxIndirect() function:
Declare Long GlobalAlloc In kernel32 Long wFlags, Long dwBytes  
Declare Long GlobalFree In kernel32 Long hMem 
Declare Long GlobalLock In kernel32 Long hMem
Declare Long GlobalUnlock In kernel32 Long hMem
Declare Long lstrcpy In kernel32 Long lpDest, String @lpSrc
Declare Long MessageBoxIndirect in Win32API String lpMsgBoxParams

Local MsgBoxParams, cText, cCaption, hText, hCaption, pText, pCaption

*!*	typedef struct {
*!*	  UINT      cbSize;						4 bytes
*!*	  HWND      hwndOwner;					4 bytes
*!*	  HINSTANCE hInstance;					4 bytes
*!*	  LPCTSTR   lpszText;					4 bytes
*!*	  LPCTSTR   lpszCaption;				4 bytes
*!*	  DWORD     dwStyle;					4 bytes
*!*	  LPCTSTR   lpszIcon;					4 bytes
*!*	  DWORD_PTR dwContextHelpId;			4 bytes
*!*	  MSGBOXCALLBACK lpfnMsgBoxCallback;	4 bytes
*!*	  DWORD     dwLanguageId;				4 bytes
*!*	} MSGBOXPARAMS, *PMSGBOXPARAMS;			40 bytes total

cText = "Nothing difficult, isn't it?" + Chr(0)
cCaption = "MessageBoxIndirect from VFP" + Chr(0)
hText = GlobalAlloc(0, Len(cText))
hCaption = GlobalAlloc(0, Len(cCaption))
pText = GlobalLock(hText)
pCaption = GlobalLock(hCaption)
lstrcpy(pText, cText)
lstrcpy(pCaption, cCaption)

MsgBoxParams = DWORD(40) + Replicate(Chr(0), 8)
MsgBoxParams = MsgBoxParams + DWORD(pText)
MsgBoxParams = MsgBoxParams + DWORD(pCaption)
MsgBoxParams = MsgBoxParams + DWORD(32 + 4)
MsgBoxParams = MsgBoxParams + Replicate(Chr(0), 16)

? MessageBoxIndirect(MsgBoxParams)

GlobalFree(hText)
GlobalFree(hCaption)

Function DWORD(lnValue)
Local byte(4)
If lnValue < 0
	lnValue = lnValue + 4294967296
EndIf
byte(1) = lnValue % 256
byte(2) = BitRShift(lnValue, 8) % 256
byte(3) = BitRShift(lnValue, 16) % 256
byte(4) = BitRShift(lnValue, 24) % 256
Return Chr(byte(1))+Chr(byte(2))+Chr(byte(3))+Chr(byte(4))
HTH,
Alexander
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform