|
in case DLL need to inform application of something changed.
callback is better for this case?.
|
|
|
|
|
An unequivocal YES! Sending window messages is about the least flexible thing you can use because it's limited to being used only with Windows applications that have a message pump. That keeps you from using it in Console apps, Service apps, and all web applications.
|
|
|
|
|
wizQ wrote: in case DLL need to inform application of something changed. I think you misunderstand the role of a support library. A library (whether .lib or .dll) is a set of passive functions that are only activated when called from an application (Console or Windows). So it is unlikely that they would be able to "know" when anything happened that needed to be communicated to other applications.
|
|
|
|
|
//TestDll2.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl NS::A::A(int (__cdecl*)(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >))" (__imp_??0A@NS@@QEAA@P6AHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@Z) referenced in function main
=====file TestDll2.cpp=====
#include <iostream>
#include "..\\MyDll\\MyDll.h"
using namespace std;
using namespace NS;
int Print(string str);
int main()
{
NS::A* a = new NS::A(Print);
NS::printDlgt("Hello World!");
}
int Print(string str)
{
cout << str << endl;
return 0;
} MyDll project files
=====MyDll.cpp=====
#include "pch.h"
#include "MyDll.h"
namespace NS
{
PrintDelegate printDlgt;
A::A(PrintDelegate print_Dlgt)
{
NS::printDlgt = print_Dlgt;
}
}
=====MyDll.h=====
#include <iostream>
#ifndef MYDLL_H
#define MYDLL_H
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif
using namespace std;
typedef int (*PrintDelegate)(string str);
namespace NS
{
extern PrintDelegate printDlgt;
class MYDLL_API A
{
public:
A(PrintDelegate print_Dlgt);
};
}
#endif
|
|
|
|
|
Oscar K. wrote: //MYDLL_EXPORTS is set in C++\Preprocessor
What do you mean by that? MYDLL_EXPORTS should only be defined in MyDll.cpp, just before the #include "MyDll.h" . You also need to ensure that you add MyDll.lib to the linker options in your build.
[edit]
On reflection I think maybe the definition of extern PrintDelegate printDlgt; is not correct. I think it should also by declared with MYDLL_API .
I will try and test this later today.
[/edit]
modified 17-Mar-24 5:19am.
|
|
|
|
|
#define MYDLL_EXPORTS is already set in Debug\Properties\C++\Preprocessor
#define MYDLL_EXPORTS in MyDll.cpp invokes macro redefinition
extern PrintDelegate printDlgt in MyDll.h is usual decision, that's how it's done
|
|
|
|
|
Oscar K. wrote: #define MYDLL_EXPORTS in MyDll.cpp invokes macro redefinition You should only have it in one place, and inside the dll implementation file (MyDll.cpp) is the better choice.
Oscar K. wrote: extern PrintDelegate printDlgt in MyDll.h is usual decision, that's how it's done Correct, but that only makes it visible to the build of the DLL. When you build your test code the it is declared extern which the compiler accepts as it should be defined in another compilation unit, as part of the build of the main program. But when you try to link the program the linker cannot find where that item is actually defined because it only exists in the DLL. And since it has not been exported it is not listed in the lib or exp files.
|
|
|
|
|
I added extern PrintDelegate NS::printDlgt; to TestDll2.cpp, but I have got again error unresolved external. I see class A (MyDll.dll) in Dll viewer.
|
|
|
|
|
And you will continue to get that error until you create the object inside the namespace and use the MYDLL_API export prefix. As I have said more than once, you cannot use extern on an item that only exists in a DLL.
|
|
|
|
|
I changed extern PrintDelegate printDlgt;
to
extern MYDLL_API PrintDelegate printDlgt;
Now it works properly
Thanks Richard
|
|
|
|
|
Hi,
How can I get zonal id like "America/New_York" in c++?
|
|
|
|
|
|
no, this will return result in DWORD, I am looking for zone name in a string.
|
|
|
|
|
|
I am facing some problems to install the java compiler. actually in my knowledge I have installed the java compiler and also edited the enviorment variables on my pc.
PS E:\java> gcc main.java
gcc.exe: error: main.java: Java compiler not installed on this system
PS E:\java>
|
|
|
|
|
Perhaps, the Java Discussion Boards[^] would be a better place for this.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Anyway, as far as I know. The java compiler is called javac . Hence, the correct command line should be:
javac main.java
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
You are right. Thanks Bro
|
|
|
|
|
And you are welcome!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
My secondary windows (output, find results, ... ) are all misplaced.
For example, when I do a search in files and I click on a result, instead of showing the code window in a new tab next to my other source code windows; it opens up a tab in the search window.
(if it makes sense)
Any Ideas ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
What version of VS?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The latest (not preview version)
It looks like the windows are all tools windows or all are not tools windows.
alt-tab cycles between all of them.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I thought there was an option in Tools/Options to reset the window layout.
If that doesn't work, you can do a Repair from the VS Installer, and that will surely set everything back to the way it was out of the box.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Try Tools/Customize; down should drop the list of (most unticked) options for the interface look. Mine's defaulted at "standard", the only ticked box. But there's a hayrick-load of other untested to toss your implements into and have a go.
(have not tried this suggestion ... too timid a developer I'm afraid)
|
|
|
|
|
This is an observation rather than a question - if it's not appropriate I will happily delete it.
I was wondering what would happen if multiple calls were made to SentNotifyMessage() (where the receiving window is owned by a different thread) during the period that the receiving thread was still processing the first such message it received. My guess as that the thread would be deemed hung and that SendNotifyMessage() would fail. Wrong!
The documentation says "...If the window was created by a different thread, SendNotifyMessage passes the message to the window procedure and returns immediately; it does not wait for the window procedure to finish processing the message."
Saying that it "passes the message" I think makes it clear that the message doesn't go into the same queue as messages posted with PostMessage().
I set up an experiment (on Windows 10) where the thread which owns the window 'hangs' itself (simply by sitting in a tight loop waiting for a period time to expire) for a substantial period of time when it first receives a message. The thread which sends the messages sits in a loop continuously sending a large number of messages (using SendMessageNotify). Using TRACE output to monitor what was happening I could see that all of the calls to SendMessageNotify() succeeded and happened whilst the receiver was hung processing the the first message. When that hung period expired it then received all of the remaining sent messages in succession. This worked with 100,000 "queued" messages. I was surprised. Windows obviously queues these messages and can cope with a very large number of them.
|
|
|
|