Re: Critical section shared betwen dll and main program



"Ben Voigt [C++ MVP]" wrote:
Or have you a way to call
InitializeCriticalSection/EnterCriticalSection/LeaveCriticalSection
without
passing a pointer to the kernel32.dll?

In this case, usually the executable is statically linked against
kernel32.lib. I am discussing the case of dynamic (user specific) DLL
loading and passing PCRITICAL_SECTION between (possibly) old version of DLL
and an executable which was build in newer environment. The key factor here
is that old DLL was not rebuilt.

"Ben Voigt [C++ MVP]" wrote:
Not a problem, because CRITICAL_SECTION in each module must match the
Win32 API definition, in which case they are certainly compatible with
each other.

Agree. But if structure values change, both modules should be recompiled in
a newer environment (in case if pointers to structures are exposed for
external usage), if this is not done, the bug case appears.

--
Volodymyr
NG tips:
http://msmvps.com/blogs/v_scherbina/pages/microsoft-newsgroups-tips.aspx
"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message
news:uYYkCSYUIHA.5132@xxxxxxxxxxxxxxxxxxxxxxx

"Volodymyr Shcherbyna" <v_scherbina@xxxxxxxxxxxxxxx> wrote in message
news:eunYTAUUIHA.5496@xxxxxxxxxxxxxxxxxxxxxxx
Actually, I would not suggest to pass pointer to any structure between
different components like EXE and DLL.

I guess you aren't using Win32 then. Or have you a way to call
InitializeCriticalSection/EnterCriticalSection/LeaveCriticalSection
without passing a pointer to the kernel32.dll?


Because there is a theoretical chance of incompatible ABE (Application
Binary Environment) bug. Even taking into account, that CRITICAL_SECTION
was not changed since 9x, there always exists a possibility that it might
change, and the code will have a very hidden and weird bug, when DLL uses
old version of CRITICAL_SECTION and passes a pointer to it which is used
in EXE, which was compiled in a newer environment, with another
CRITICAL_SECTION. This of course is a weird situation, but one should
keep in mind such kind of possibility.

Not a problem, because CRITICAL_SECTION in each module must match the
Win32 API definition, in which case they are certainly compatible with
each other.


--
VolodymyrNG tips:
http://msmvps.com/blogs/v_scherbina/pages/microsoft-newsgroups-tips.aspx
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:uSXppnyTIHA.5264@xxxxxxxxxxxxxxxxxxxxxxx
"Mandi" <mandi@xxxxxxxxxxxx> wrote in message
news:%23nauFfyTIHA.4476@xxxxxxxxxxxxxxxxxxxxxxx
I use critical section in my dll. Now I want to refer to it in my Main
executable?
Is there a way to do it?


There is no problem with passing its address between exe and DLL.

--
Scott McPhillips [VC++ MVP]






.



Relevant Pages

  • Re: Critical section shared betwen dll and main program
    ... passing a pointer to the kernel32.dll? ... DLL and an executable which was build in newer environment. ... module *must* use that system definition. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Segmentation fault when accessing function in a DLL
    ... You are passing a NULL pointer to the function 'USMC_Init' is that what the function expects or does it expect a pointer to a valid ... To pass a valid pointer initialize at least one field of the structure before passing it to USMC_Init. ... I am trying to use functions in a windows DLL for controlling stepper motor hardware. ... I read carefully the external interfacing section in Matlab help and related articles in several ...
    (comp.soft-sys.matlab)
  • Re: Critical section shared betwen dll and main program
    ... different components like EXE and DLL. ... old version of CRITICAL_SECTION and passes a pointer to it which is used ... There is no problem with passing its address between exe and DLL. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: GetDC() Fails in DLL.
    ... >I have created SDI Application and one DLL. ... >I am passing View Pointer to DLL, ... Are you mixing a release mode DLL with a debug mode EXE? ...
    (microsoft.public.vc.mfc)
  • Passing function as parameter?
    ... how would I go about passing a function as parameter? ... My goal is to send a pointer to a function to a dll and have that dll call that function. ...
    (microsoft.public.vc.language)