|
reasley wrote: Thanks. I just found that function, finally, on the MSDN site. One question I have on this function though is that if I use this function as if it were a WinMain function and put a loop in it to process graphics animations, is there a way to gracefully close the dll when the screen saver turns off? For instance, when the mouse is moved the screen saver should exit, but if the dll has a graphics processing loop in it's DllMain function, will the screen saver still receive the exit notification? And if it does, I would guess that then I would want to call the FreeLibrary function to release the dll, or possibly the FreeLibraryAndExitThread function so that it closes the screen saver as well. But will I be able to release the resources created by the dll or is it done automatically when the FreeLibary function is called? I did not see any type of "WinProc" funciton for the dll so that I can process messages.
For what you want, you don't want to use DLLMain. DllMain basically initializes the dll. You can pretty much leave the default code the wizard gives you in it alone. What you will want is to create a function that will spawn a thread to do operations. That thread will need to keep an event handle and check it periodically to see if it needs to exit. To cause the thread to exit, you will call a separate method that will trigger the event.
The basic flow will look like this:
In the main application (pseudo-code)
<br />
LoadLibrary("MyDll.dll")<br />
MyStartFunc = GetProcAddress("Start")<br />
MyStopFunc = GetProcAddress("Stop")<br />
<br />
MyStartFunc()<br />
<br />
MyStopFunc()<br />
<br />
FreeLibrary(MyDll)<br />
In the Dll
<br />
MyEvent = NULL<br />
<br />
function Start<br />
[<br />
MyEvent = CreateEvent()<br />
StartThread(MyGraphicLoop)<br />
]<br />
<br />
function MyGraphicLoop<br />
[<br />
if (MyEvent is Triggered)<br />
exit<br />
else<br />
RenderGraphics()<br />
]<br />
<br />
function Stop<br />
[<br />
TriggerEvent(MyEvent)<br />
]<br />
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 16:31 Wednesday 31st May, 2006
|
|
|
|
|
That is great to know! So I can still have all of my code in the dll I just use the dll to spawn a thread that will do the rendering/calculation loop. That doesn't sound to difficult to do. Thanks a lot Zac and everyone else who responded.
~REasley
Conquering the world one bit at a time.
|
|
|
|
|
I am using Visual Studio 2005 Standard, C++.
How to set IDE for Multithreading?
Some say Properties /Code Generation, but I don't see on my IDE.
Could anyone help me?
Thanks!
Yonggoo
|
|
|
|
|
Yonggoo wrote: How to set IDE for Multithreading?
Uuh ? What do you mean exactly ? There is not such thing as 'IDE for multithreading'.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Yonggoo wrote: I am using Visual Studio 2005 Standard, C++.
How to set IDE for Multithreading?
Some say Properties /Code Generation, but I don't see on my IDE.
Could anyone help me?
Thanks!
That is where it is in VC6. You just need to select the multithreaded libraries. There is a drop-down list (can't remember where in the .Net versions) that allows you to select "Debug", "Debug Multithreaded", "Single Threaded", etc. Select the proper multithreaded library.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I found it!
In Visual Studio 2005 Standard IDE, there is option about multithreaded.
In general condition,
Properties/configuration properties/C/C++/code generation/runtime library
But, in some conditions that option is not available,like when we chose 'empty project'.
As long as I know!
Thanks!
Yonggoo
-- modified at 16:57 Wednesday 31st May, 2006
|
|
|
|
|
Using Vis C/C++, Vis Stu 6.0
I am writing code for PCI communications.
I need to loop around at 1000Hz or so to
check for incoming data.
Looping with Sleep(1) puts a 15.6 millisec
delay, so it seems as if it uses the
nefarious Tick Timer. This is way too slow
for this app.
Is there any way to make precision timing,
or sleep with true resulution at 1 millisec
or smaller?
Many thanks,
Robert
|
|
|
|
|
Robert Palma Jr. wrote: Is there any way to make precision timing,
or sleep with true resulution at 1 millisec
or smaller?
No, because Windows is not a real-time OS. See here for more.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Robert Palma Jr. wrote: Is there any way to make precision timing,
or sleep with true resulution at 1 millisec
or smaller?
Sleep relinquishes the processor from the current thread for at least the time you give it. It does NOT mean that it will regain CPU time in 1 ms if you call Sleep(1); it does mean that you will not regain CPU time in less than 1 ms. You are basically telling the OS that you don't need to work for at least a certain amount of time so it can let someone else work.
Windows does have a high resolution timer, but it has been a while since I even bothered with it. Check out this book.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have a client application that is calling a method from an ActiveX control. Inside the ActiveX control I have a worker thread doing some additional processing. However, the ActiveX method that is called from the client application is blocking my worker thread. I need to verify a global value from the worker thread while inside that ActiveX method call? Any ideas on how to this?
Thanks
|
|
|
|
|
what inside activex is block thread?
Kuphryn
|
|
|
|
|
The ActiveX method is blocking the worker thread inside the ActiveX control!
|
|
|
|
|
control resides inside thread?
Kuphryn
|
|
|
|
|
Using spy++ I find a window.
But, I need to get the screen coords for the window so I can place a the mouse there. Can anyone tell me how or what API function I can use to get the actual screen coordinates of the window.
Please
this is what I currently have
RECT myRect2 = new RECT();
GetWindowRect(hwnd, out myRect2);
int posx = (myRect2.right - myRect2.left) / 2;
int posy = (myRect2.bottom - myRect2.top) / 2;
where hwnd is the handle of the wind returned from EnumChildWindows
Is this right or wrong? My SendInput doesn't appear to be working correctly.
1 line of code equals many bugs. So don't write any!!
-- modified at 14:50 Wednesday 31st May, 2006
|
|
|
|
|
Ista wrote: Is this right or wrong?
It's not the most efficient, nor is it syntactically correct. Try:
RECT myRect2;
GetWindowRect(hwnd, &myRect2);
Ista wrote: int posx = (myRect2.right - myRect2.left) / 2;
int posy = (myRect2.bottom - myRect2.top) / 2;
This finds the center of the window. Is this what you want?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
heres what i have. and yes its ugly.
( this is c# callung user32.dll ) I asked in here, think the C++ gurus would have an easier time with this.
RECT myRect2 = new RECT();
GetWindowRect(hwnd, out myRect2);
int posx = (myRect2.right - myRect2.left) / 2;
int posy = (myRect2.bottom - myRect2.top) / 2;
MOUSEINPUT mi = new MOUSEINPUT();
mi.dx = posx + myRect2.left;
mi.dy = posy + myRect2.top;
mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
mi.mouseData = INPUT_MOUSE;
int cb = Marshal.SizeOf(mi);
SendInput(INPUT_MOUSE, ref mi, cb);
This window is a button I have created in another application.
SO what I want is to click the left button of the mouse anywhere in the button.
But when I run it, I don't think its working because the button event isn't firing. Although if I use PostMessage, it works fine.
I think im just getting coords relative to the window and not the screen.
Please help.
Thanks, Nick
1 line of code equals many bugs. So don't write any!!
-- modified at 15:21 Wednesday 31st May, 2006
|
|
|
|
|
If you are just trying to cause the message handler for your button click to get called, just use Send/PostMessage with your window handle for the button (which you will still have to obtain, but you already have the app window handle, so it won't be too hard from there).
If you actually want to move the mouse there, try setting the focus to either the app or to the button before calling SendInput. You will also have to call SendInput 2 different times: once to move the mouse to the correct position and once to simulate the button press.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm trying to write a program with an interface similar to a disc defrag. It needs to show 10,000 boxs, 100x100 pixs each. The boxs will show a sequence of colors 1 at a time. I'm switching from VB6 to VC++ and I can't figure out how to create 10,000 images that I can access individually with a index. I'm so lost, can anyone help me?
Overwelmed++
-- modified at 15:49 Wednesday 31st May, 2006
|
|
|
|
|
hiho
cause i'm much more working on unix systems
i just don't know how i can connect and do some SQL statements to a database like postgresql or mysql?
for example, using linux i use libpq API with funktions like PQconnectdb or PQexec to connect or execute a query
but how does this work under windows?
can i use the same API on windows systems?
i'm sure there are many guys here who know how this stuff works, but since i work most time with linux i just have no idea on how to do database programming on windows
any articles or hints would be great
thx@ll
|
|
|
|
|
ThinkingPrometheus wrote: but how does this work under windows?
See here.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
that seems a good resource
but, just cause of interest:
is there only odbc on windows?
and for better understanding:
is odbc just a API which is able to "talk" to databases?
or can odbc do much more than just manage sql and its results? (i'm not sure about what i'm expecting, that's why i ask )
|
|
|
|
|
ThinkingPrometheus wrote: is there only odbc on windows?
No. See here.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
|
|
Hi, everybody
I need a POP3 server code in C or C++. Could you please suggest me where I can find such code?
Thanks in advance
-- modified at 14:33 Wednesday 31st May, 2006
|
|
|
|