|
Your code sample doesn't make sense, but it looks like you're not using BSTR correctly. You also appear to not have the ATL or OLE headers included, so that's giving you the majority of the compiler errors. Start simple:
BSTR bs = SysAllocString ( L"Hello Bob" );
SysFreeString ( bs );
bs = NULL;
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I used #include <atlconv.h>.. was that not right? What is the name of the includes I need?
thanks in advance.
-- modified at 1:21 Sunday 9th April, 2006
EDIT: I took another look at the second guide and figured out what I needed to do. Thanks a lot for the all the help. This is solved.
best regards
|
|
|
|
|
Hi borono,
Still having problems? Have a look here[^]. This function will allow you to convert a char* which is a C string to a BSTR.
Maybe there are better methods of doing this from VB though.
|
|
|
|
|
I believe I have found the answer you are looking for right here[^]. Now if you don't have this up and working by the end of the day I am personaly going to come and steal your computer
|
|
|
|
|
haha, no worries. I do have it working, here is what I did.
DLL Side:
#include <comdef.h>
template< class T >
BSTR ToBSTR( T a_Str )
{
return( _bstr_t(a_Str).copy() ) ;
}
extern "C" void __stdcall stat( void (*cb) (u_short**) )
{
char dao[100];
sprintf(dao,"UDP: %d",udp);
BSTR l_Temp = ToBSTR(dao);
BSTR bs = SysAllocString ( l_Temp );
cb( &bs );
SysFreeString ( bs );
bs = NULL;
}
VB Side:
Declare Sub stat Lib "mydll.dll" (ByVal funcptr As Long)
'
Sub CallbackFunction(ByRef numb As String)
Form1.Label1.Caption = numb
End Sub
works great! computer saved.
best regards
-- modified at 10:37 Sunday 9th April, 2006
EDIT: thought it would be a good idea to include the conversion function, considering without it, this code is useless. Bold represents the modificiation.
|
|
|
|
|
borono wrote: haha, no worries. I do have it working,
Damnit, I just put my shoes on too. Congrats, you spent long enough on this, now you can move onto the next problem :P
|
|
|
|
|
haha, how'd you know I'd be having a problem? I am, but it is all design. This I really am horrible with. When it comes to design, you will see many programmers all designing their GUIs pretty much the same way. Not because there is a lack of creativity but because it works. There is indeed, at least, three ways to accomplish anything. They have found the first, I am concerned with the latter.
best regards
|
|
|
|
|
Hello!
In my program I have something like this:
<br />
volatile stop;<br />
<br />
void SetStop()<br />
{<br />
stop = true;<br />
while (stop) Sleep(100);<br />
}<br />
<br />
while (true)<br />
{<br />
if (stop) <br />
{<br />
stop = false;<br />
return;<br />
}<br />
Sleep(10);<br />
}<br />
But while the main thread waits for the
variable stop to be reset, this never
happens! Why not?
If I don't wait for it, the program opens
a message box (which sais that the thread
was not stopped; by use of a CSingleLock),
and when it is open, the thread resumes...
Alex
|
|
|
|
|
|
You forgot the variable type, bool is ok. So add bool after volatile;
volatile bool stop;
|
|
|
|
|
Thank you for your answer.
I only forgot it in my question, that's not the problem.
I also used the Debugger to go through the code.
But when I use "Run to Cursor" within the Thread-Loop
or set an breakpoint when I entered the waiting loop,
it never gets called.
Alex
|
|
|
|
|
I'm doing a hands-on learning process to communicate with a USB-GPS unit (specifically a Garmin GPS-18USB). I've searched a number of sources including Garmin's "SDK", and have figured out how to talk the language. I can manually get PVT info from the unit, etc., but would now like to move to the next step, that is, to make an MFC-based program "drive" the unit and display the data. The unit outputs data every second when instructed to do so.
I open the channel with CreateFile to produce a handle, and DeviceIoControl. I can send commands to the unit and receive data back. But I don't understand how to deal with asynchronous data and leave the GUI operating normally, that is, if I'm unsure when/if data may be received, I can't just call a Read or DeviceIoControl function: it will never return if there's no data available. I believe I need a worker thread to gather the data, but therein lies a problem:
How does one determine if data is available for a Read operation, read it, then get it back to the main app periodically for display? What's the right technique for managing this, knowing that perhaps the application may be asked to stop or close during a period that a Read operation is awaiting input? What functions may be used to allow a thread to be non-blocking, to respond to other messages?
|
|
|
|
|
Have a look at overlapped i/o (the last param in createfile , readfile etc).
You can then wait on events (read happened, thread should die, etc) in your worker thread.
Them when something interesting has been sent by the GPS unit, you can assemble it in your thread, and use PostMessage to kick your UI thread...
I know that's a short version....
Iain.
|
|
|
|
|
Thanks,
I've already tried the overlapped IO, so I guess I should use WaitForMultipleObjects: 1. the read complete and 2. the thread ends, etc.? I'm thinking that just waiting for a single object (the read happened) would still hang up?? Or will WaitForSingleObject@0mS in some kind of loop work?
|
|
|
|
|
What I've done is:
HANDLE hEvents [2];
...
hEvent [0] = Overlapped.hEvent;
hEvent [1] = hBailFromThread;
dwWait = WaitForMultipleEvents (hEvent, 2, INFINITE);
if (dwWait == WAIT1)
{
tidy up
return
}
do stuff ()
loop back.
and so on.
and to kill the thread:
SignalEvent (hBail);
WaitForSingleEvent (hThread, sensibletime);
etc.
I hope thatb helped a little.
Iain.#
|
|
|
|
|
Gracious thanks for the quick replies. That makes sense (I think ) and I'm going to give it a go tomorrow. I'll note if I get it working...
Mike
|
|
|
|
|
Hi all
I have such code :
...
__int32 x = 0;
char *str = "1234";
x = (str[0],str[1],str[2],str[3]);
...
What will be the value of x and why ?
thank you in advance
|
|
|
|
|
|
Thanks for reply Mike, but it is not a homework.
I also know that x will be 52, but why ?
|
|
|
|
|
Look up how the comma operator works.
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
I got the following problem: I got a DC in which I need to put an image comprised of more bitmaps. However, if I paint the bitmaps one by one, I get some flicker.
So I need 1 memory DC to paint the bitmaps with. 1 memory DC to paint them in. And then this last memory DC will get bitblt-ed on the third and real DC.
But the problem is that when I can't paint from the first DC to the second. I select the bitmaps in the first DC and bitblt them in the second. But when I do my stuff and bitblt the second DC upon the third, I get only white. Anybody got any clue what I'm messing up here?
I didn't include code 'cause my routine is rather complicated and it's not written in C++ but here is something that may be of use:
1. I create both memory DCs using "CreateCompatibleDC(REALDC)".
2. I select bitmaps in the first DC using "SelectObject (hdcMemory, myBITMAP)".
3. I simply bitblt from first DC to second DC at the desired coordinates.
4. I repeat steps 2. and 3. for 4 images, bitblt-ed at various coordinates within the second DC.
5. Now I bitblt the second DC in the real DC, the third one, the visual source.
All is white................
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
can u BitBlt() first memory DC to real DC properly?
default size of memory DC is 1x1 pixels.
did u set suitable size for all other memory DCs?
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
I can't paint directly to the real DC 'cause I need to put more images. So I need an intermediate DC in which to dump the pictures piece by piece and then bitblt in the original DC.
I set the size of the memory DC by selecting a bitmap of the desired size in it. Is that correct.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
|
I don't know what you're trying to suggest here and I don't think I'm gonna like the sound of it. But please, give it a shot ::- ).
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|