|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
How can I know the version of an console application executable ? (obviously, this exe is not made it by me)
|
|
|
|
|
Unless the executable contains version information you can't. It is possible to add version information in a resource definition file when building a console app, but few people do so. Right click the .exe and check the properties.
|
|
|
|
|
Yes, I have checked properties in Windows, Explorer, but show me nothing. I thought there is another way to find it.
|
|
|
|
|
In that case it does not contain 'standard' version information. There may be other information held in the program but only the creators will know where it is.
|
|
|
|
|
does it have by chance a "-v" or "-version" or "/version" command line parameter ?
I'd rather be phishing!
|
|
|
|
|
How do you know that such executable actually has a version?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Hi!
I try to implement a callback function within a dll, which triggers an assigned function in the main application. I want to trigger this "event" in the main app from within the dll.
Here is my code from the dll:
extern "C" __declspec(dllexport) void funcA(const unsigned long long a, const unsigned long long b);
extern "C"
{
typedef void(__stdcall* callback_t)(unsigned int halfbeast);
__declspec(dllexport) void public_func_taking_callback(callback_t evHnd)
{
evHnd(333);
}
}
void funcA(
const unsigned long long a,
const unsigned long long b)
{
if(a>10)
callback_t(public_func_taking_callback);
}
Here is the code I use in the main application to load the library and attach to the functions:
typedef void (__stdcall *eventCallback)(unsigned int miau);
typedef void (__stdcall *setCallback)(eventCallback evHnd);
void __stdcall CallB(unsigned int);
void __fastcall TForm1::Button1Click(TObject *Sender)
{
signed int retval;
unsigned int i;
char txt[7];
unsigned long long a,index;
UnicodeString USt;
HINSTANCE dllHandle=NULL;
dllHandle = LoadLibrary(L"test.dll");
if (!dllHandle){
ShowMessage("Could not load test.dll");
Form1->Close();
}
else{
void (__stdcall* funcA)(const unsigned long long a, const unsigned long long b);
funcA=(void(__stdcall*)(const unsigned long long a, const unsigned long long b))GetProcAddress(dllHandle,"funcA");
setCallback values=(setCallback)GetProcAddress(dllHandle, "public_func_taking_callback");
if(values != NULL){
values(&CallB);
}
if(!funcA){
Memo1->Text="No handle to function found.";
}
else{
funcA(1,1);
funcA(100,100);
}
FreeLibrary(dllHandle);
}
}
void __stdcall CallB(unsigned int halfbeast){
ShowMessage("triggered");
}
What happens is unfortunately not what I wanted:
1) In the very moment the line "values(&CallB);" is executed, CallB is called. This is not what I wanted, I justed wanted to give the callback pointer of the dll to my function CallB.
2) CallB is not called when the line "funcA(100,100);" is executed. Most likely there is something wrong with the function call within the dll, but I cannot see it...
|
|
|
|
|
1. That is correct. At that point, values is set to public_func_taking_callback , which takes the address of a function and immediately calls it.
2. funcA calls callback_t , but callback_t has never been set to any value.
To be honest, I find it difficult to understand your code, so I may have still missed something. However, you should be able to see the exact sequence of events by running the code in the debugger.
|
|
|
|
|
Hi Richard,
thanks for the answers. Yes I can debug it, but it doesn't help me much, since I don't understand why it behaves that way.
1.) OK, got it. Unfortunately then I do not know, how I pass the address of the function of CallB to the dll. I want the dll to call CallB() in the moment callback_t is called.
Most likely I confuse here something, but I find it very hard to understand the syntax. It seems even harder since it is wrong
I wasn't able to find any C++ examples for that.
2.) I thought I set it to public_func_taking_callback, but obviously this is not the case.
Maybe I should explain again, what I try to do:
In my main application I want to declare a function. This function should be registered in the dll as a callback function. When during run time in the dll some criteria match ( if(a>10) ) the dll should call the function in the main application and execute it.
|
|
|
|
|
Bodo2407 wrote: I don't understand why it behaves that way. It behaves that way because that is the way you have written the code.
1. So you need to change the code in public_func_taking_callback as follows:
__declspec(dllexport) void public_func_taking_callback(callback_t evHnd)
{
callback_t = evHnd;
}
And you need to change funcA to:
if(a>10)
callback_t(a);
Again, make these changes and then step through the code in the debugger to check that it is correct.
|
|
|
|
|
Hi Richard,
thanks a lot, but unfortunately it cannot compile:
__declspec(dllexport) void public_func_taking_callback(callback_t evHnd)
{
callback_t = evHnd;
}
Failure given:
-Error C2513 'void (__stdcall *)(unsigned int)': no variable declared before '='
So the typedef earlier doesn't work or... ?
|
|
|
|
|
callback_t is a type, not a function.
In your DLL , you do need a variable of such a type, in order to store the user function address.
Something similar to (not tested)
typedef void (__stdcall* callback_t) (unsigned int halfbeast);
static callback_t s_user_function = nullptr;
extern "C" __declspec(dllexport) void funcA(const unsigned long long a, const unsigned long long b);
extern "C"
{
__declspec(dllexport) void public_func_taking_callback(callback_t evHnd)
{
s_user_function = evHnd;
}
}
void funcA(
const unsigned long long a,
const unsigned long long b)
{
if(a>10 && s_user_function != nullptr)
s_user_function(333);
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks Carlo, I missed that.
|
|
|
|
|
Thanks a lot guys! It works now!
I really appreciate your help.
Now it also makes much more sense to me. 
|
|
|
|
|
As you pointed out, the OP code looked a bit confused.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
CPallini wrote: a bit confused I assumed that was just me. 
|
|
|
|
|
OK, now I experience another issue with it, I'm sorry.
Hopefully you can help me here as well.
I now want to call the callback function if an timer expires. Therefore I create an timer in a function I call from the main application. I store the handles to the timer and the timer queue globally in static variables.
static HANDLE gDoneEvent;
static HANDLE hTimer = NULL;
static HANDLE hTimerQueue = NULL;
int arg = 123;
VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
{
if (lpParam == NULL)
{
return;
}
else
{
if(s_user_function!=nullptr)
s_user_function(12);
}
}
Now, in some function called from the main application, I allocate the timer and start it:
char timer_init(void)
{
gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (NULL == gDoneEvent)
{
return 1;
}
hTimerQueue = CreateTimerQueue();
if (NULL == hTimerQueue)
{
return 2;
}
CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK)TimerRoutine, &arg, 3000, 10000, 0);
WaitForSingleObject(gDoneEvent, INFINITE);
}
As you can see, I don't close the handles and delete the timer queue on purpose.
Everything works fine as long as the process waits. The callback in the main application is called.
If I comment out the line with WaitForSingleObject I'll get an access exception, although I stored all the handles globally. Teh exception occurs with the timing the timer would have. So most likely it tries to call the callback of the timer function but something is missing.
What is it I'm overlooking?
I need the dll running, not waiting inside a fucntion for a timer...
|
|
|
|
|
Bodo2407 wrote: I need the dll running, not waiting inside a fucntion for a timer.. I am not sure what you mean by that. When you create a timer, it is designed to call some function after a specified period of time, either once or repeatedly. The reason for having the call to WaitForSingleObject , is in case the main code needs the timer event to complete some action first. But it is not necessary if the remainder of the code does not rely on the actions of the timer event.
|
|
|
|
|
Hi Richard,
yes, I know that. I did put that in, because I got the exception and wanted to try the example code. This worked two times, so I thought it must be caused by leaving the function. Unfortunately thsi is not the case:
After some debugging runs it seems that (in rare cases) it works a few times, but most likely it crashes immediately. So the observation I made that it is working if I call WaitForSingleObject isn't correct, it can crash randomly with or without.
Unfortunately when it crashs the program pointer isn't on frame any more, so I don't see why it does that.
One observation I made is that the handle of gDoneEvent is allocated in an entirely different address room (0x000003b0) than the other two handles hTimer and hTimerQueue(0x008b8928 and 0x008bsomething) which seems strange to me, since I thought allocated event should be also pretty close to the handles, but obviously it is not.
modified 13hrs ago.
|
|
|
|
|
Those numbers do not mean anything, except to the operating system.
|
|
|
|
|
Problem 1 — Flawed MAC designs (11 marks) For this problem, you need to carefully trace through the given MAC algorithms, and
|
|
|
|
|
No idea what that is supposed to be. Maybe you lost connection while typing.
|
|
|
|
|
You never asked a question, but based on what other people are doing lately, it seems you're just trying to post your homework assignment from Chegg Study, thinking someone is going to write the code for you.
That's not going to happen.
|
|
|
|
|