|
This should get you started:
#include "stdafx.h"
#pragma data_seg(".MySeg")
int g_ImInAnotherSegment = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.MySeg,RW")// Make section readable and writable.
int main(int argc, char* argv[])
{
return 0;
}
Steve
|
|
|
|
|
my application currently reads and uses data from files at a location on the host machine using fstream
what i would like to do is include these files and their data as resources so that the application does not rely on the data being stored on the host machine
i am using FindResource, LoadResource, LockResource etc but i'm having trouble passing the actual data content straight to fstream - is this possible??
<br />
FindResource(..);<br />
LoadResource(..);<br />
char* ptr = (char*) LockResource(..);<br />
<br />
fstream.open(ptr,ofstream::binary);<br />
any help would be greatly appreciated - i'm pretty new to resources!
|
|
|
|
|
bimgot wrote: char* ptr = (char*) LockResource(..);
What do you want to do with ptr at this point?
bimgot wrote: fstream.open(ptr,ofstream::binary);
The first argument to fstream 's constructor is the name of the file to open, not the actual data within the file. Perhaps that is where your confusion lies.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
as i understand LockResource returns a pointer to the first byte of the data stored in the resource.. currently i use fstream to read, validate and store some wave file data so that it can be used to play back the wave file
since the open function of fstream takes a char* for the name of the file to open, i wondered if a char* for the resource would work in the same way
i think my confusion is as you say with fstream but since the class i want to use the data from the resource with is based on fstream, i wondered if there was a solution that doesnt involve re-writing the class..
|
|
|
|
|
I was wondering how the operating system handles this (if it's at all possible). I was thinking that the main thread could hook itself to an event (that when signaled, outputs the word "foo" to console) and then spawn a child thread that does some work. When the child thread is done work, it would raise a signal to the event that the main thread would catch, before the child thread terminates.
The concept I'm having trouble working around is the following:
Main Thread Child Thread
|
|--------------------------->
| |
| |
| |
|<---------------------------
|
|
When the child thread raises the signal, and the main thread catches it, would it stop whatever it's currently executing to write the word "foo" to console, then continue on with whatever it's doing?
|
|
|
|
|
Sure, if you posted the data back to the main thread through for instance a user-defined windows message.
I do this sort of thing a lot in for instance socket programming, like pressing the "Connect" button of a chat program. Without having a separate thread, the whole program could freeze up for several seconds as the socket attempted to connect, since it's a blocking call.
KR
|
|
|
|
|
The main thread would have to be waiting on a synchronisation object, a message queue or event in order to respond to the child threads signal. You can't preemptively interrupt any thread except to suspend it, resume it or terminate it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Well, I was thinking of using this method to hook the main thread to the event:
Native C++ Event Handling
However, hooking to an event doesn't imply that your main thread can no longer do anything but wait for the event, which led to my above question.
|
|
|
|
|
I don't know if this would work. I suspect the event function would get called on the child thread or a temporary thread rather than on the main thread.
Although Microsoft labels all this up as 'Native' you'll notice the bracketed [event_source(native)] attributes indicating managed extensions. I guess this probably works like the COM event system where the child thread will get temporarily suspended when it raises the event and then the rutime will actually scrape up (probably from a pool ) a separate system thread to call the event handler on, releasing the child thread to go its merry way after the hand off of any parameters. You could do this in straight C++ but being able to hand off any set of parameters is, I suspect, what's going to require the compiler magic indicated by [event_source(native)]. It's going to have to write some code for you based on the definition of the event class
Personally I would use a straight forward Event object and have the main thread poll (WaitForSingleObject with a short timeout) for it periodically.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
That's something I could consider, but what if you were to wait for it periodically and do work from the main thread in between these periods? If the event were to be signaled while you aren't waiting, you'd miss it, right (in that case, everything would go haywire)?
|
|
|
|
|
No the event would remain set and then the next time you waited for it the wait would succeed. The only way it would fail is if the client thread destroyed the event object on exit. That would be bad. It's not necessary though as the Event has to be shared with the main thread in order for this to work so the main thread can handle clean up.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I create a none-block socket to connect to another,someone would tell me why the connect function would aways return FALSE?
And how should I do such equal thing?
Thanks.
|
|
|
|
|
connect() does not return a boolean. It returns an int.
A return value of 0 indicates success. A return value of SOCKET_ERROR indicates an error.
For a non-blocking socket, if you get a return value SOCKET_ERROR, you should check if the error
is WSAEWOULDBLOCK (using WSAGetLastError(). WSAEWOULDBLOCK means the connect hasn't completed yet
so you won't know if there's an error until you receive a completion notification/event.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi all,
I have the following problem, I include the following header files:
#include <sql.h>
#include <sqlext.h>
But I receive this error:
[C++ Error] sqltypes.h(123): E2146 Need an identifier to declare
@ line 123 : typedef unsigned long ULONG;
Can anyone help me ??
Many Thanks
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Suggest you do a Google search on "E2146 Need an identifier". It appears to have something to do with the definition of winsock.h vs winsock2.h
hope this helps you.
John P.
|
|
|
|
|
jparken wrote: It appears to have something to do with the definition of winsock.h vs winsock2.h
When why am I receiving the error in my sqltypes.h file ??
Google result:
Results 1 - 10 of about 59 for E2146 Need an identifier.
jparken wrote: hope this helps you.
Thanks
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Looking through those headers I can't see why you'd get that message.
Do you have WIN32 defined (probably in the project settings preprocessor defines)? You should
Also, maybe try including windows.h before those includes, but I can't readily see where that
would make a difference.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
But you're using header files from the Windows Platform SDK, right? Or does Borland have
their own version of Windows headers?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
That's a library not a header
Take a look through sqltypes.h - does it refer to "WIN32"? What about "HWND"?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yes, all of the header files are there.
sql.h
sql_1.h
sqlext.h
sqltypes.h
....
....
And all of the states "Microsoft Corporation" at to the top.
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Mark Salsbery wrote: Take a look through sqltypes.h - does it refer to "WIN32"? What about "HWND"?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
How can I determine what type of media is associated with a letter in Windows?
Example:
A: is floppy,
B: not used,
C: fixed drive,
D: CD-ROM,
etc.
In VC++ 6 please.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Take a look at GetDriveType() .
|
|
|
|