Re: how to export global variable in C dll?



I've found a fix for my problem, but I'm still looking for
documentation on declaring global variables for C (and C++ now too)
DLLs.

It appears that one should export global variables in C DLLs the same
way as one does in C++ DLLs, prefixing the global declarations with
'__declspec( exp/imp )'.

In my case, I see linking errors when doing it because I had a file
in my C DLL project that ended with the .cpp file extension. Even
though all types were C, the C++ compiler must have been used to
compile my DLL. I don't know why I see a link error when using the
export prefix, but changing my .cpp to have the .c file extension
fixed the problem.

Happy coding.



On Apr 9, 5:12 pm, Cyrfer <cyr...@xxxxxxxxx> wrote:
Hi,
I've written a DLL using C (not C++) and I'm trying to export its
global variables so that they can be read by client code. I'm having
trouble to find documentation about how to do this. My attempts to
use 'extern' and/or '__declspec' on the global variables result in
linker errors when building my DLL. Will someone please point me to a
reference which address global variables in C dlls?

Thanks!

.



Relevant Pages

  • Re: mutual dependent DLLs and global variables
    ... I agree that the best solution is to reduce the dependency between ... and came up with DLLs... ... >>initialize all global variables A, however since GlobA1 uses a global ...
    (microsoft.public.vc.mfc)
  • Re: Why wont this work ?
    ... The documentation can be very confusing, one needs to 'learn' how to ... struggling with Delphi, and i was told that Delphi is just as easy as basic, ... AX DLLs and OCXes are really just normal DLLs containing COM objects ... InstalledFlag:Boolean = False; ...
    (alt.comp.lang.borland-delphi)
  • Re: Finding parent process of a DLL
    ... Aren't DLLs considered modules themselves? ... DLLs, EXEs, Drivers are Modules. ... EXEs are typically based at 0x40000 so their HMODULE is 0x40000). ... The documentation for GetModuleFileName is a bit misleading since it says ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Program Startup State
    ... The information about DLLs is under "dllmain". ... Once you get down under the runtime libraries, documentation ... Gary Chanson ... Abolish Public Schools ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Prevent other programmers from using my dll component?
    ... the libraries so they can only be used by your applications. ... the process of trying to get Microsoft to give us better documentation ... > Since I need to distribute all the exe and dlls to the user PC, ...
    (microsoft.public.dotnet.general)

Loading