|
KEL3 wrote: In fact the correct code for that would be:
f.Write (&FileName,sizeof(FileName));
Wrong. This would still write the address of FileName to the file. Why is it so hard to code something like:
f.Write(FileName, FileName.GetLength());
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes, sorry.
I meant that,
f.Write (&FileName,sizeof(FileName));
would be the correct code to save the
object in the file, not the string that
it has allocated. I would be more clear
in future!
But the code I posted above:
f.Write(FileName.GetBuffer(20), FileName.GetLength()+1);
works. I have done it before (that's why
I decided to answer, despite the fact
I'm not an expert). Your piece of code
does the same with less code! I just
didn't have in mind that CString could
be so easily type-casted into LPCSTR
and then to void* .
But you must also use the +1 , so
that the '\0' character be written.
This is needed if you don't know the size
of the string from the beginning.
No mean to argue, you are right.
Thanks for helping me in the past too. Remember this:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2117813&df=100&fr=15724.5#xx2117813xx[^]
kostas KEL
|
|
|
|
|
I have a question to calculate gcd of two numbers.I have tried a lot but cant do it. I am very new to Visual C++. How can I do it. I have to do it without using functions. And Please i want it very urgent. Got only few hours to submit.
|
|
|
|
|
Read up on the Euclidean algorithm
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
shabbi89 wrote: ...but cant do it.
Even on paper?
shabbi89 wrote: And Please i want it very urgent. Got only few hours to submit.
Don't let your emergencies become someone else's problem.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Using visual c++ .NET, is there a simple way to isolate functions from
user input during runtime? (This is done with a command-line program)
AIM: So functions can be calculated upon
EXAMPLE FUNCTION: Sin(x+y(Cos(y))
Thanks for any help!
-- modified at 22:04 Saturday 20th October, 2007
J ker
HA! HA! HA!
|
|
|
|
|
no, you have to write your own string parser.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
G'day,
Is there an easy trick to make a dll re-entrant, e.g. each time the dll is called, the caller gets its own data area? The functions in the dll are written in plain C, no classes are involved.
Regards,
Henk
|
|
|
|
|
DLLs can be written without any class, only in C. This is done easily with VC++.
|
|
|
|
|
henk21cm wrote: each time the dll is called, the caller gets its own data area?
I'm not sure what you mean here.
Each process that is linked to DLL gets its own instances of all the
DLLs data, except that data that's explicitly shared somehow.
Except for special shared data, you manage your data in the DLL
just like you do in an EXE. How would each "caller gets its own data area"
in an EXE? Automatic/stack-based variables, some kind of passed data struct,
etc.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you can implement "dllmain" function in your dll.
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved
);
this function is called when a DLL is attached/detached to a process or thread.
You may use this to do what you want.
|
|
|
|
|
Thanks folks,
A proposed solution is:
karle wrote: BOOL WINAPI DllMain(
This is -apart from the name of the argument hinstDLL- exactly the same as the intiation code in this dll.
Maybe some more detailed description of what is happening.
The dll is called by a web application written in Delphi. The main task of the dll is to read a file and to store the data within this file in both a global struct and a pointer to double. Delphi can access and change this data by means of functions in this dll.
When several users simultaneously access each of them their own files, the data is overwritten by each consecutive 'read' call, so user 1 sees the data of user 2. Since this is unwanted behaviour, the work around was to add three functions:
Islocked(); Lock(); and Unlock();
Before trying to read or access data, the Delphi application checks whether IsLocked(); is false and then Locks the dll. After processing your data, the
Delphi application Unlocks the dll.
Not pretty, however it works. I was wondering whether there is a more elegant solution?
Regards,
Henk
21 cm: the universal wavelength of neutral hydrogen
|
|
|
|
|
My understanding is that DLLs are reentrant. That's sort of the idea behind a DLL in the first place. The thread that makes a call into the DLL has its own stack, and since data is not shared between thread stacks, each call has its own data area. However, if you have, for example, a memory mapped file, a named pipe, a resource handle to say a GDI brush, then you have a resource that's shared by the OS across threads. This has nothing to do with the DLL, but accessing that resource inside of the DLL can cause threading issues to arise, since the various callers of the DLL run asynchronously.
For example, suppose your DLL retrieves a handle to brush or writes, reads, then deletes the contents of a memory mapped file. One thread calls into the DLL and, before it exits, is swapped out by the task manager. That thread's stack is set aside and its place of execution within the DLL is marked, then the new thread begins execution. Say the first thread wrote data to the file, but did not read or delete its data. The new thread comes in and writes its data, but when it reads the data back, it gets its data and the data from the previous thread. Then the second thread deletes its data and the data placed there from the previous thread. When the original thread is swapped back in, there is no data there to read back anymore.
A DLL is just a function that is made available to call by any executable (more generally, thread) on the OS.
Disclaimer: I'm not a software engineer, but I play one at my office.
Without darkness, there are no dreams.
-Karla Kuban
|
|
|
|
|
Hello,
I have several functions (can be classes) which I want to choose at runtime using a string.
Example:
void name1(){blah blah}
and I want to use one string (for example "name1") to call this specific function.
One way would be to create a (the code below is not correct, just for illustration)
map<string, functions=""> Map_Functions;
What I don't like about that is that I have to fill the map manually:
Map_Functions["name1"] = &name1;
Is there a way to fill the map at run time using just the string "name1"?
thanks for any help,
mauree
|
|
|
|
|
mauree wrote: Is there a way to fill the map at run time using just the string "name1"?
No.
|
|
|
|
|
Nemanja Trifunovic wrote: No.
Actually my question was: is there an easy way to do it... because I know of one way to do it: using dynamic symbol loader I look up the function name from a .so or a .dll and load the map with the result of that.
The problem is, to make it portable is painful... possible but painful.
Again... any help appreciated.
|
|
|
|
|
mauree wrote: using dynamic symbol loader I look up the function name from a .so or a .dll and load the map with the result of that.
Well, good luck with that
|
|
|
|
|
I'm not very fit into Dlls but, I think you can list the functions that are in a dll, like reading from top to bottom and taking the name, but I don't know how to make the relationship you need for calling them dinamically.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I tried this:
void CMyLottoView::OnInitialUpdate()<br />
{<br />
CHtmlView::OnInitialUpdate();<br />
<br />
LoadFromResource(IDR_HTML_INDEX);<br />
CSize sz(600, 600);<br />
SetScrollSizes(MM_TEXT, 1000, &sz);<br />
}
I want to be from scroll size to defaultscroll size. but it does not work. Help me on this topic.
-- modified at 5:11 Sunday 21st October, 2007
|
|
|
|
|
I made it with
CSize sizeTotal;
sizeTotal.cx = 950; sizeTotal.cy = 1400;
SetScrollSizes(MM_TEXT, sizeTotal);
and worked for me.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Good thanks. I'd like to do const size CView. Need to the CScrollSizes or what? That is
cs.style &= ~(FWS_ADDTOTITLE | WS_THICKFRAME | WS_MAXIMIZEBOX);
My CView shows only my const size and scrolling. That is how can i modify this application with no scroll. Do you understand me?
|
|
|
|
|
I don't really understand what you want to say. But I try:
If you want your view not having scroll bars, you should put the size of the workspace inside the limits of you frame. If you want to have the scrolls, you give the scroll size bigger than frame space.
I mean:
cs.cx = 800; cs.cy = 600;
CSize sizeTotal;
sizeTotal.cx = 785; sizeTotal.cy = 585;
SetScrollSizes(MM_TEXT, sizeTotal);
should set the workspace without having scrolls. But...
cs.cx = 800; cs.cy = 600;
CSize sizeTotal;
sizeTotal.cx = 1600; sizeTotal.cy = 1200;
SetScrollSizes(MM_TEXT, sizeTotal);
you will have a workspace two times bigger than your frame, so you will have scroll bars
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Thanks friend.
I have a question for you again. How can I do that Internet Explorer "dialog re-bar" for showing left side of the frame window?.. It must seems to be vertical.
-- modified at 7:09 Tuesday 23rd October, 2007
|
|
|
|
|
I have never worked witht the internet explorer (just as user, not programming) sorry
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|