|
I build the dll that having a global variable. my requirement is to load the dll in
same application many times . every thing is fine but problem is that global variable using
copy the same value in all instances . how to avoid it . I must need that global variable.
Ashish
|
|
|
|
|
See here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Here's a solution I got from led mike: Use a class with a static member variable. It will be the same variable for all DLL instances.
|
|
|
|
|
I can't believe it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
As I recall led mike's suggestion solved a problem I had been working on for hours. It makes sense; the linker resolves external references, and all references to a static class member should resolve to the same address.
|
|
|
|
|
Alan Balkany wrote: It makes sense; the linker resolves external references, and all references to a static class member should resolve to the same address.
It does NOT make sense, all references to a static class member should resolve to the same address only inside the same memory space (i.e. the same process). Of course this is going on my arrogant assumptions...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
But when the different instances of the DLL are linked, aren't they in the same process? (When you call a method in a DLL, it doesn't automatically start another process to do this.)
|
|
|
|
|
Well, maybe I've misunderstood. I thought the OP was talking about multiple instances of the same application (i.e. different processes) and not multiple instances of the same DLL inside the same process. BTW what is the point of loading the same DLL multiple times?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
So, you're attempting to re-load the same DLL multiple times, in the same process?
But you want them to act independently?
And, in your case, the global variable isn't doing that -- it's the same each time?
Is that what you are asking?
I think that the deal is -- you can't load the same DLL multiple times within the same process.
The answer you seek?
Get rid of the global variable in the DLL and find another way to accomplish what it accomplishes.
?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
Hi all,
I m working on SDI type application,use splitter to divede view in two parts.
at any time all application are not responding and all area is black.
if i click any other position than this error comes.
Unhandled exception at 0x00507ebe in Employee Planner.exe: 0xC0000005: Access violation reading location 0x00000050.
if i use break option than it point out at this location ::
in winocc.cpp
DWORD CWnd::GetExStyle() const
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
return (DWORD)GetWindowLong(m_hWnd, GWL_EXSTYLE);
else
return m_pCtrlSite->GetExStyle();
}
i dont know wat its is please tell me what can i do.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Here ? ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
Something is really wrong. Your window doesnt exist!!! Check the object!!
Greetings from Germany
|
|
|
|
|
Hi all,
I am getting seg fault when trying this piece of code.
I'm not getting what is went wrong here.
void fun(int* ptr){
ptr = (int*)malloc(sizeof(int));
}
int main(){
int *ptr = NULL;
fun(ptr);
*ptr = 5; //seg fault
cout<<*ptr;
}
|
|
|
|
|
Well of course, you are passing a pointer to a function (a certain address, which is NULL). In the function, you assign a new address to this pointer but the pointer is only a copy of the original, so, your original pointer is not affected. To make things more easier, think that a pointer is just a variable that holds an address. When you pass this variable to a function, the function makes a copy of it. It still points to the same address but if you change the address, you only modify the local copy.
|
|
|
|
|
ok
then what change is required here. so that i can i can put some value into memory allocated in fun() function.
|
|
|
|
|
Exactly the same as if it was a variable: pass it by reference.
|
|
|
|
|
Like this???
void fun(int* ptr){
ptr = (int*)malloc(sizeof(int));
}
int main(){
int ptr;
fun(&ptr);
ptr = 5;
cout<<ptr;
}
I dont think so..
probably you mean something else.. that i am not getting.
modified on Monday, September 29, 2008 8:40 AM
|
|
|
|
|
Use &.
void fun(int*&ptr)
{
}
then in the main function
fun(ptr)
Is it working now?
modified 7-Mar-17 16:31pm.
|
|
|
|
|
Well, you need something a bit more elaborated (plain C ):
void myAlloc(int ** ptr)
{
*ptr = (int *) malloc(sizeof(int));
}
int main()
{
int * pMyInt;
myAlloc( &pMyInt);
*pMyInt = 5;
printf("%d\n", *pMyInt);
free( pMyInt)
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes, this is exactly what I was trying to do..
Thanks a lot, all of you
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
when i initialize a list iterator with an integer, it gives compile error as follows:
list <int >::iterator iter;
iter = 0; //this gives an error c2679 when build in release mode
but the same code works fine when i build in debug mode.
why? can any body put some light on this?
(am using visual studio 2005)
thank u
|
|
|
|
|
what if you initialize the iterator correctly ?
list <int>::iterator iter;
iter = mylist.begin();
where mylist is an instance of the class list<int>
|
|
|
|
|
This[^] explains why (debug mode has the _HAS_ITERATOR_DEBUGGING macro set)
In general you shouldn't create iterators from pointers (0 is being treated as the NULL pointer). If you want to ensure that the iterator references nothing then set it via mylist.end().
Graham
Librarians rule, Ook!
modified on Monday, September 29, 2008 9:08 AM
|
|
|
|