|
ok. it seems to do the work. but there is still a problem with pointers types. is there a simple way to handle them?
for example, in one structure i am holding a property from type char*. when writing the object to the file, the pointer is stored and not the string held in it, which is, of course - useless.
|
|
|
|
|
Of course, you cannot use this when your structure hold pointers !!!
What is a pointer ? A pointer is just a 32 bits variable that holds an adress (at this adress, the data is stored). So, when you write the pointer to the file, it just stores the adress and not the data.
If you want to save your structure, it would be a better idea to encapsulate the save/load functions inside your structure (if you don't use the MFC and/or don't want to use serialisation, you can do it yourself):
typedef struct
{
int DataCount;
int* pSomeData;
void SaveData(HANDLE* hFile)
{
DWORD NumberOfBytesWritten;
WriteFile(hFile, &DataCount, sizeof(int), &NumberOfBytesWritten, NULL);
WriteFile(hFile, pSomeData, sizeof(int)*DataCount, &NumberOfBytesWritten, NULL);
}
void LoadData(HANDLE* hFile)
{
DWORD NumberOfBytesRead;
ReadFile(hFile, &DataCount, sizeof(int), &NumberOfBytesRead, NULL);
pSomeData = new int[DataCount];
ReadFile(hFile, pSomeData, sizeof(int))*DataCount, &NumberOfBytesRead, NULL);
}
} YourStruct;
And from the outside it will look like:
YourStruct* pStruct = new YourStruct;
pStruct->SaveData(hFile);
Or for loading:
YourStruct* pStruct = new YourStruct;
pStruct->LoadData(hFile);
Hope this helps
|
|
|
|
|
|
Hi all
How can I share some memory allocated in one process by another process by using dll.?
Is there any way to accomlish this using other methods
Thanks in advance
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Maybe you can use memory-mapped files ? You can open a file-mapping object in memory from one process and access data in it within another process.
Take a look at the MSDN for file mapping (and file mapping functions...)
Hope this helps
|
|
|
|
|
Or...even look more locally...
http://www.codeproject.com/threads/ipc_tute.asp
http://www.codeproject.com/win32/cmemmap.asp
http://www.codeproject.com/threads/csharedstruct.asp
http://www.codeproject.com/threads/sm.asp
http://www.codeproject.com/threads/sharedmemipc.asp
http://www.codeproject.com/threads/memmapipc1.asp
http://www.codeproject.com/threads/SharedMemory_IPC_Threads.asp
That should get you pointed in the right direction
|
|
|
|
|
The recommended way to share data, is memory mapped files. Look up the functions CreateFileMapping and MapViewOfFile.
You could also create a shared section in your dll, I can't remember the procedure, but you should be able to find it on MSDN by searching for '#pragma' and 'shared'.
I don't think you can share memory allocated by new() or malloc() though...
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Hi
Thank you all, it was of great help.
See you all later
bye
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
I am using Visual Studio .NET 2003.
I would like to convert a CString into a std::string. With Visual C++ Ver 6.0 one could just use the std::string constructor, but now I get an error message with VS .NET 2003. Does anybody know?
I am the handsome one in the crowd.
|
|
|
|
|
Maybe forcing the conversion to a LPCSTR ?
Cstring cs=...;
std::string s=(LPCSTR)cs;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Scenario :- I want to connect to multiple servers from a single client at a time and collect some information.
Is it possible to do this using CAsyncSocket in a single thread for each server?
When is CAsynSocket used instead of CSocket ?
Thanks in Advance,
Ajoy.
U Live And Let Others Live
|
|
|
|
|
Hi,
Be carefull with multithreading, CLOSING, I've experinced the pain.PLAN PROPERLY.
Sujan
|
|
|
|
|
Hello,
MSDN says the following about CSocket and CASyncSocket:
"You should probably consider using CAsyncSocket if you want Windows Sockets' ease of dealing with multiple network protocols in an MFC application but do not want to sacrifice flexibility. You might also feel that you can get better efficiency by programming the communications more directly yourself than you could using the more general alternative model of class CSocket."
So CSocket is a more easy to use class at the cost of some overhead. If you don't need high speed connections, multi network protocols, I'd stick with CSocket.
Hope this helps
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
|
I didn't knew that..
Als an alternative, you can use a Socket class found here on codeproject. There are many here, so it should be easy to find one.
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
I'm using code from MSDN article "Handling HTML Element Events" but DIID_HTMLElementEvents2 interface seems to be undefined.
It's not declared in mshtml.h, only DIID_HTMLElementEvents.
Where is DIID_HTMLElementEvents2 declared?
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
I have write an application, use VC++ connect to Oracle database, and use Crystal Report to view data and print
Any one can help me, how to connect to Oracle and use Crystal report.
thanks.
|
|
|
|
|
The same problem i also have, but instead of Oracle database i am using MS Access as the database. Can Anybode let me know how to get the same thing using MS Access as the database.
I know how to connect to MS Acces database, but what i want to know is how to use Crystal Report to view data and print.
Regards,
Pankaj
|
|
|
|
|
VC++ fronend, MS Access backend with Seagate Crystal Report sample code can be downloaded at
|
|
|
|
|
Where?!?
[insert witty comment here]
bdiamond
|
|
|
|
|
could you , show me where to download sameple code
thank a ton
|
|
|
|
|
sorry, here's the link
http://www.geocities.com/jcynion/jcynion_codes.htm
|
|
|
|
|
Thanks you vey much, but i live in VietNam, so the proxy
not allow me to go out ( especially geocities.com)
could you send to me that code
thank a ton
|
|
|
|
|
sorry, here's the link
http://www.geocities.com/jcynion/jcynion_codes.htm
|
|
|
|
|
I get an error "the library PDBDAO.DLL could not be found" when i show or print report.
|
|
|
|