|
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
|
|
|
|
|
I want get network status on local host in real time.
I used API, IsNetworkalive, InternetGetConnectedStateEx,
but it seems those api didn't work correctly.
my computer connect to a wireless AP.when i drop the connect,the return value of api was wrong.
please get me some advise or soure code.
thanks.
|
|
|
|
|
What happens if you run this code?
DWORD dwType;
BOOL m_bConnect;
m_bConnect = InternetGetConnectedState ( &dwType, 0 );
if (m_bConnect)
if ( dwType & INTERNET_CONNECTION_OFFLINE )
bConnect = FALSE;
|
|
|
|
|
what do u meen by hot spot
!~~~~!
|
|
|
|
|
Are you talking about the mouse cursor?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
It is a location whose temperature exceeds that of its surroundings.
|
|
|
|
|
See this[^] thread does your answer?
|
|
|
|
|
'WS_MAXIMIZED' : undeclared identifie. Given a bug. What can i do?
|
|
|
|
|
Change it to WS_MAXIMIZE ?
|
|
|
|