|
Hi
Well I'm close to insanity so it's time to ask you, the gurus
I've made a DLL in Visual C++ and can successfully call it from within Visual Basic. However, I can't pass function arguments. For instance, one of my functions is:
SetWindowPosition(LONG handle, float width, float height)
Which is declared in VB as:
SetWindowPosition(ByVal handle As Long, ByVal width As Single, ByVal height As Single)
Strangely the last argument is passed correctly, the rest take on erroneous values such as 9.72*e-39. Why would one argument (eg. height) be passed correctly but width is garbage? Guessing it had something to do with the stack, and misaligned arguments (ie 8 byte long reading 4 byte int), I've tried a simple function with just one argument (Single->float as per VB4DLL.txt) but even this produces garbage. With the above function I've also tried converting from Long to long, unsigned int, int, etc. Any ideas?
Regards
Brendan
(For the record I have done the following:
1/ Using a DEF file
EXPORTS
SetWindowPosition //note I don't have @1 is that a problem?
2/ Using extern "C" __declspec(dllexport) before function
3/ no __stdcall statements but it still runs...
|
|
|
|
|
Well like most problems the solution is simple. I'll post it here to ease the agony on others who might have to trawl through mountains of messages.
In VB a function that returns a variable is declared as 'Function' and a function that doesn't return a variable is declared as 'Sub'. So the correct declaration is
Public Declare Sub DoSomething Lib "DLL.dll" (ByVal dooba As Long)
for a function that doesn't return a value. and,
Public Declare Function DoSomething Lib "DLL.dll" (ByVal dooba As Long)
for a function that does return a value.
Obviously it stuffs the stack up if you don't do it right, and this is what produced the erroneous values.
|
|
|
|
|
Sorry for not being as clear on my last post =(
Is there a way to give focus to your program even when you don't control the program that DOES have focus?
|
|
|
|
|
The function you want is SetForegroundWindow() , although in 98/ME/2K there are restrictions on when you can actually make your app come to the foreground. The docs have all the details.
--Mike--
http://home.inreach.com/mdunn/
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
--Buffy
|
|
|
|
|
This doesn't seem to work in any of my tests and I can't find out why in the documentation.
Thanks,
Ed
|
|
|
|
|
Hi Ed,
Michael is correct, however you might have to have a thread in the bakground
which decides when and if this needs to be done.
{
while(WaitForSingleObject(..., 5000)!=Signaled)
{
HWND h = FindWindow(...);
SetForegroundWindow(h);
}
}
I hope I understood your question.
Jules
|
|
|
|
|
I'm using this code to create a dialog box:
CEdmondDlg *dlg;
dlg = new CEdmondDlg;
dlg->Create(IDD_EDMOND_DIALOG);
this creates the dialog but it doesn't have focus. How can I fix this?
|
|
|
|
|
dlg->SetFocus();
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
This doesn't work.. I think maybe because my whole program doesn't have focus when it is called. Is there a way to give focus to your program even when you don't control the program that DOES have focus?
|
|
|
|
|
Then probably your whole program should grab the focus in a similar wayt first. Why doesn't it have the focus, is it a background task ?
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
How to get handle of an edit control of another different running application?
|
|
|
|
|
How to get handle of an edit control of another running application?
|
|
|
|
|
I don't think that's possible. Search the MSDN on-line library for the keyword "handles". There's an article that
touches on that subject. The problem is that, even if you could get the handle, you probably couldn't do anything
with it because the object is in the address space of the other process. A handle to an object in process A cannot
normally be successfully referenced in process B because the object may, or may not, be the same object.
|
|
|
|
|
When assigning a CString to a BSTR, does CString contain a copy of the BSTR or is it a pointer to the same BSTR?
If I later destroy the original BSTR does this make the CString unusable?
Example: CString strAnotherCopy;
BSTR b;
b = SysAllocStringByteLen("Hello World", 12);
strAnotherCopy = b;
SysFreeString(b);
At this point, is strAnotherCopy still valid?
|
|
|
|
|
Yes, CString contains a copy of the BSTR, but not stored as a BSTR.
|
|
|
|
|
Hi
I have a producer thread of the following form:
while (1)
{
g_cs.Lock();
if (GetPkt()) g_PktEvent.SetEvent();
while (index==FULL)
{
g_cs.Unlock();
WaitForSingleObject(g_BufferEmptyEvent,INFINITE);
break;
}
g_cs.Unlock();
}
and a consumer thread as follows:
while (1)
{
g_cs.Lock();
if (index>0) g_BufferEmptyEvent.SetEvent();
while (index==0)
{
g_cs.Unlock();
WaitForSingleObject(g_PktEvent,INFINITE);
break;
}
g_cs.Unlock();
}
When I run the program, the threads block after some time (the buffer remains empty). The producer thread does not produce any pkt to place in the buffer.
Can anyone please help me find out where the bug is?
Thanks a lot
|
|
|
|
|
There are numerous problems with your code:
First, in your producer thread, there's no reason for the second while loop. Since you never loop, you call break at the end of it no matter what. This can be achieved with an if statement instead.
Second, in the case of index==FULL, then you will call Unlock() twice while only calling Lock() once. That will cause all kinds of problems.
The same applies for your consumer thread.
But the real problem here is likely that you are in what's called a deadlock, or race condition. Your consumer thread is waiting in WaitForSingleObject for a packet ready event, and your producer is waiting for a buffer empty event. Since both threads are waiting at the same time, they wait indefinately.
|
|
|
|
|
Thanks for replying.
I actually changed my code so that I'm now using an if statement instead of while. I also modified the code such that I only call Unlock() once. But I'm still having the same problem.
Any suggestions?
Thanks again
|
|
|
|
|
Yes, I already told you in my first response.
You're in a deadlock, you need to make sure you never get into a deadlock by changing your algorithm so that you are never causing two waits to be waiting on each other.
|
|
|
|
|
Could anyone tell me how to hibernate machine from my program?
|
|
|
|
|
I'm experimenting the usage of bitmaps. I started by downloading an example project from codeproject and I'm trying to modify it:
http://www.codeproject.com/miscctrl/oscope.asp
I would like the oscilloscope to plot the points starting from the left side of the screen, ending at the right side.
At the moment, the bitmap points are plotted from right to left (I would like it to be the opposite). I already added a multiple graphs' support to the program, but can't solve this simple direction problem.
Can someone give me a hint on how to fix the situation, please?
|
|
|
|
|
Desktop also a window in VC++. Can we write a program to capture it, and can we change the caption of start button.
If so please tell me the procedure.
Thanking you
|
|
|
|
|
It's possible, but this requires a lot of work, since the start button is an owner drawn button. You would need to subclass the button, then do your own painting.
What you would need to do is enumerate the desktop windows child windows looking for the Shell_TrayWnd, then enumerate the Shell_TrayWnd's child windows looking for a window with the button class. Once you get that HWND, can then sublcass it into a CButton using CButton::Attach
|
|
|
|
|
If you would like an example go to: http://homepage1.nifty.com/kazubon/tclock/indexe.html
|
|
|
|
|
Can we create voice recognition software in VC++. If so please tell me the procidures.
Thanking You
|
|
|
|