|
Bram van Kampen
|
|
|
|
|
|
It means:
You designed the Software, and You wrote the Code, so You are the best person in the world to know what's it supposed to do or not do in the firstplace. None of us are in that priviledged position.
Bram van Kampen
|
|
|
|
|
Hello evryone.
How can I pass arguments call info + simple function address to a certain code that would
then be able to succefully call that function ???
For example I have a function like :
void sendHello(char* hello,int destID);
I want to pass to a certain code block A, the address of that function by mean of a void* variable, and
also pass someother "metadata" about arguments order and types, so that the code block A can
succeed to callback that function.
Is there sort of something that would like :
A::storeFunction( void*, metadata??)
such for example I can easily call :
A::storeFunction(sendHello,{{"byString","hello"},{"byInt","destID"}});
before the code block A can somehow, at a certain time needed succed to call the function he stored ??
??
Thank u in advance.
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
I'm not sure if I fully understood your question but it would be interesting for you if you serach for "functors" or "function objects". Instead of working with functions directly, you wrap then into a class so that it is easier to manipulate.
|
|
|
|
|
Thank you Cédric for the reply.
I took a look at functors yesterday.
Unfortunately the problem is not solved : (The code below uses functor implementation found in
cppfunctor.sourceforge.net) :
Using functors then I suppose to declare a variable in block A such :
event< void, char*, int> functorObj; in order to be used as wrapper for the
void sendHello function (void sendHello(char* hello,int destID)) (see example in first msg).
then I would set it as :
functorObj.assign( mkFunctor<void,>::create(sendHello) );
OK This is good, but as you notice the code block A that holds the functor declaration presupposed the prior information of the function arguments (their type and order).
The functors would help me avoid the case where I would need to define a type for each function pointer :
typedef void (*Type1) (char*,int);
typedef void (*Type2) (char*,char*);
..etc
instead just worry about the arguments number, types and order at the object instantiation :
event< void, char*, int> functorObj1;
event< void, char*, char*> functorObj2;
But this is exactly not what I want. Instead I'd like to remove the hypothesis that the code block A have the prioir information about functions arguments types and orders.
..
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
hINTModuleState wrote: Instead I'd like to remove the hypothesis that the code block A have the prioir information about functions arguments types and orders.
That's something really strange: when you want to 'execute' a function, you always knows which arguments you have to supply to the function.
So in your case you are telling me that somewhere you 'define' a function (code block) but leave the arguments definition for later. That feels strange because how could then your block of code receive anything if it is not known at that time ?
|
|
|
|
|
hINTModuleState wrote: I want to pass to a certain code block A, the address of that function by mean of a void* variable, and
also pass someother "metadata" about arguments order and types, so that the code block A can
succeed to callback that function.
I Don't know if I understand your question correctly, but it occurs to me that you want to:
1) Declare a pointer to a function taking an Argument;
2) Refer to that pointer later by calling the code the function pointer refers to, using the arguments supplied.
You quote Class or Structure Member functions, Their'e unbeleavibly more tricky. Best first get familiar with global functions:-
As Follows:-
<br />
typedef void (*PFN_MYFUNCTION)(LPCSTR pStr);<br />
<br />
PFN_MYFUNCTION mf=puts;<br />
mf("Hello World");<br />
<br />
Bram van Kampen
modified on Monday, November 3, 2008 9:59 PM
|
|
|
|
|
Thank you for your reply.
Unfortrunately your solution is not sufficient.
OK It is good as far as I'd like only to remove the hypothesis that the code block A knows the exact implementation of the function : ie just declare a pointer like you put, then an external code block
B would arrive and bring the "puts" function and pass it as a value for the pointer mf in A.
What I'm much worried to do, instead, is to also remove the prior information about arguments' types and order.
In your solution : PFN_MYFUNCTION is a type for the (void)(LPCTSTR) functions only.
Instead how can develop a code block A where may be I would only store a void*, then externally
set that void* with functions of any type with the only possiblity to pass arugument info metadat at exection time ??
Thank you in advance.
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
well, If I understand correctly, you could create structures to hold the arguments. Pass as argument a pointer to such a structure, and inside your function recast to a pointer to the correct type of structure.
Another possibility is:
<br />
typedef DWORD (*PFN_MYFUNCTION)(int Type,...);<br />
There Type specifies the type of argument list to expect. You must however be able to have the calling context and the callee agreeing on the argument list.
Bram van Kampen
|
|
|
|
|
Hello everybody,
a certain external library or object in memory disabled sometimes my CDialog Application.
I like to handle this message, so i can write into a log file some informations
to find out what time or why this disable is executed.
a if(pMsg->message == WM_ENABLE) into the PreTranslateMessage don't fire if i execute
manually a EnableWindow(FALSE);
Is there a possibility?
Big thanks for help
|
|
|
|
|
I would appreciate some advise. I need to import some data into a list and incorporate this list of static data into a DLL. Can anyone advise how you would go about doing this please?
|
|
|
|
|
HANDLE is a void*, so it is an address.
How can I display the content of a HANDLE, and how can I construct it from a displayable text value ??
Thank you in advance.
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
From a programming perspective, handles are just unique numbers identifying different Windows' objects. The fact that they are memory handles to some specific windows-internal data structure is mostly irrelevant.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank u. so it is just like an int.
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
hINTModuleState wrote: HANDLE is a void*, so it is an address.
It is not a valid address in the application address space.
hINTModuleState wrote: How can I display the content of a HANDLE
You can just display its (numerical) value.
hINTModuleState wrote: how can I construct it from a displayable text value ??
??? ???
BTW if you want to play with the handles, then you must follow the rules of the game
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
it turned out to be not even a valid address anywhere, rather an access number behind which resides a pointer which holds the actual address to the actual internal structure (whether a window, or whatsoever...)
OK I 'llwith it just like an INT....
"The Awaited Saviour", Mohammed Baqir Al Sadr
|
|
|
|
|
Hi,
I am trying to load a bitmap image in a CRichEditCtrl using InsertBitmap function as:
bool CChatDlg::InsertBitmap(HWND RichEdithWnd, HBITMAP hBitmap)
{
IDataObject * pDataObject;
IOleObject * pOleObject;
IStorage * pStorage;
IOleClientSite * pOleClientSite;
LPLOCKBYTES LPLockBytes = NULL;
FORMATETC FormatEtc;
IRichEditOle * pRichEditOle;
SCODE SCode;
REOBJECT ReObject;
CLSID ClSid;
char * Texte = "";
static char Texte2[] = "";
HGLOBAL hGlobal;
CWnd pWnd;
CoInitialize(NULL);
if(OpenClipboard())
{
Texte = new char[256 + ZERO_FIN];
Texte = (CHAR *)GetClipboardData(CF_TEXT);
sprintf(Texte2, "%s", Texte);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
}
else return 0;
hGlobal = GlobalAlloc(GMEM_DDESHARE, strlen(Texte2) + 1);
Texte = (CHAR *)GlobalLock(hGlobal);
sprintf(Texte, "%s", Texte2);
GlobalUnlock(hGlobal);
m_richEdit.SendMessage(EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
if (pRichEditOle == NULL) return 0;
OleGetClipboard(&pDataObject);
if (pDataObject == NULL) return 0;
FormatEtc.cfFormat = CF_BITMAP;
FormatEtc.ptd = NULL;
FormatEtc.dwAspect = DVASPECT_CONTENT;
FormatEtc.lindex = -1;
FormatEtc.tymed = TYMED_GDI;
pRichEditOle->GetClientSite(&pOleClientSite);
if (pOleClientSite == NULL) return 0;
SCode = CreateILockBytesOnHGlobal(NULL, true, &LPLockBytes);
if (LPLockBytes == NULL) return 0;
SCode = StgCreateDocfileOnILockBytes(LPLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage);
if (pStorage == NULL) return 0;
OleCreateStaticFromData(pDataObject, IID_IOleObject, 2, &FormatEtc, pOleClientSite, pStorage, (void**)&pOleObject);
if (pOleObject == NULL) return 0;
OleSetContainedObject(pOleObject, true);
ZeroMemory(&ReObject, sizeof(REOBJECT));
ReObject.cbStruct = sizeof(REOBJECT);
SCode = pOleObject -> GetUserClassID(&ClSid);
ReObject.clsid = ClSid;
ReObject.cp = REO_CP_SELECTION;
ReObject.dvaspect = DVASPECT_CONTENT;
ReObject.poleobj = pOleObject;
ReObject.polesite = pOleClientSite;
ReObject.pstg = pStorage;
pRichEditOle -> InsertObject(&ReObject);
if(OpenClipboard())
{
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
}
else return 0;
LPLockBytes -> Release();
pRichEditOle -> Release();
pOleObject -> Release();
pOleClientSite -> Release();
pStorage -> Release();
pDataObject -> Release();
CoUninitialize();
return 1;
}
but the function call
OleCreateStaticFromData(pDataObject, IID_IOleObject, 2, &FormatEtc, pOleClientSite, pStorage, (void**)&pOleObject);
fails and return 0.
Please help me whats the problem.
Thanks In Advance.
Dhiraj Kumar Saini
|
|
|
|
|
Hi friends..
I need to show date and time both at a time in the DateTimePicker
right now i have seen all examples of DateTimePicker show to disply only date r only time at a time.
can some one help me how to show date and time both at a time in DateTimePicker. please let me know if it can be done?
thank u in advance
|
|
|
|
|
You can set custom format using SetFormat()
e.g. from msdn
CString formatStr= _T("'Today is: 'yy'/'MM'/'dd");
m_dtPicker.SetFormat(formatStr);
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
thats really nice idea.
and also is there any way that i can show date calender for date and spin control for for time at a time in the UI?
i need to show calender for date and spin control for time at a time
will that be possible?
please let me know
|
|
|
|
|
sarat12in wrote: will that be possible?
Yes, if you use the DTS_TIMEFORMAT style.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
DTS_TIMEFORMAT will only shows the time but not date calender
i need to show date calender and time spin control
any suggestion please
thank you
|
|
|
|
|
i will go with the first suggestion.
but the problem in here is.. if i mention date time format programatically with setFormat , then the display format wont get changed depends on locale
its a big problem for me.
is there any way that i can get the system format fist and pass it as a string to SetFormat? r is there any other way to handle this scenario?
Thanx in advance
|
|
|
|
|
sarat12in wrote: is there any way that i can get the system format fist and pass it as a string to SetFormat?
Yes. Use GetDateFormat() and GetTimeFormat() .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|