[Fwd: [omniORB] Repost: Why this call failed in dll?]
Bing Zhang
bzhang@sohar.com
Tue, 27 Oct 1998 12:02:12 -0800
This is a multi-part message in MIME format.
--------------0E4FD8FAA0499FE667D88942
Content-Type: text/plain; charset=gb2312
Content-Transfer-Encoding: 7bit
--------------0E4FD8FAA0499FE667D88942
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-ID: <36362648.569F11CC@sohar.com>
Date: Tue, 27 Oct 1998 12:00:08 -0800
From: Bing Zhang <bzhang@sohar.com>
X-Mailer: Mozilla 4.04 [en] (X11; I; SunOS 5.5 sun4m)
MIME-Version: 1.0
To: Sai-Lai Lo <S.Lo@orl.co.uk>
Subject: Re: [omniORB] Repost: Why this call failed in dll?
References: <3634E786.C8FB2F7A@sohar.com> <3oemru9ths.fsf@neem.cam-orl.co.uk>
Content-Type: text/plain; charset=gb2312
Content-Transfer-Encoding: 7bit
Sai-Lai,
you are right. Actually I realized this last evening after I sent out the
message. This is what I did.
The orginal services.h is
class ServiceClass {
...
};
extern ServiceClass Service;
Original file service.cc,
....
ServiceClass Service;
Now the services.h and services.cc compiled into DLL is:
class __declspec(dllexport) ServiceClass {
...
};
//extern ServiceClass Service; //Got compilation error if not commented out
file service.cc,
....
__declspec(dllexport) ServiceClass Service;
The services.h compiled with application is
class __declspec(dllimport) ServiceClass {
...
};
__declspec(dllimport) ServiceClass Service;
Everything works now.
>From your post, it seems to me that I do not have to change anything in file
services.h and services.cc compiled into dll, the services.h compiled with
application should only be
class ServiceClass {
...
};
__declspec(dllimport) ServiceClass Service;
only place needs to be changed. Is this right? BTW: I did not find the
_OMNIORB_NTDLL_IMPORT in any omniORB2 file.
If the global variable is used both by other files in the dll and application
code, how do I declare them? Since if I had
class __declspec(dllexport) ServiceClass {
...
};
extern ServiceClass Service;
in file services.h. Then I got compilation error if services.cc is
.....
__declspec(dllexport) ServiceClass Service;
This dll crap is really not that easy for a UNIX programmer trying to step into
the Window world. :)
Thanks
Bing
In the
Sai-Lai Lo wrote:
> I think the problem is that you have not qualified "extern ServiceClass
> Service" with a __declspec(dllimport) when your application code is
> compiled. In omniORB2 all global variables in the DLLs that have to be
> accessed in the application code are prefixed with the macro
> _OMNIORB_NTDLL_IMPORT which translate into __declspec(dllimport) when the
> header files are included in the application code.
>
> Don't just take my word for it. Please read up on the MSVC++ dllimport
> crap..
>
> Regards,
>
> Sai-Lai
>
> >>>>> Bing Zhang writes:
>
> > I have a very simple class in file services.h:
> > class ServiceClass {
> > unsigned long caminStartTime;
> > public:
> > ServiceClass();
> > resetStartTime(unsigned long delta);
> > unsigned long currentTime();
> > };
> > extern ServiceClass Service;
>
> > In file service.cc,
>
> > ServiceClass::ServiceClass() {
> > caminStartTime = (unsigned long) timeGetTime();
> > }
> > ServiceClass::resetStartTime(unsigned long delta) {
> > caminStartTime = delta;
> > }
> > unsigned long ServiceClass::currentTime() {
> > return (unsinged long) timeGetTime();
> > }
> > ServiceClass Service;
>
> > In my main(), I call
>
> > Service.resetStartTime(0);
>
> > This works fine if I compile my main, application codes and omniORB2
> > source code (I modified some part of omniORB codes to suit our
> > situation) together with service.cc.
>
> > But when I put the service.cc along with omniORB source code in a dll
> > and link my application code to this
> > dll, every time this call is made, it throws out a "The instruction at
> > xxxxxx reference memory at xxxxxxx. The memory can not be wrriten" error
>
> > when the statement
>
> > caminStartTime = delta;
>
> > is executed. But the call Service.currentTime() runs ok. So I think the
> > system does not want me to modify the member variable of Service, which
> > is
> > now a global variable inside the dll.
>
> > I am using vc++ 5.0 and omniORB 2.4. I built the dll by adding my source
>
> > codes to the dir.mk of omniORB.
>
> > What is wrong?
>
> --
> Dr. Sai-Lai Lo | Research Scientist
> |
> E-mail: S.Lo@orl.co.uk | Olivetti & Oracle Research Lab
> | 24a Trumpington Street
> Tel: +44 223 343000 | Cambridge CB2 1QA
> Fax: +44 223 313542 | ENGLAND
--------------0E4FD8FAA0499FE667D88942--