Trying to use a variable over multiple modules, but the compiler(1.06 Win) throws error code 4 back: Duplicated definition, g_hInst in 'common shared g_hInst as HINSTANCE
Help file says:
Variable declaration and scope modifier
Common [Shared] symbolname[()] [AS DataType] [, ...]
Declares a variable which is shared between code modules. A matching Common statement must appear in all other code modules using the variable.
Common variables cannot be initialized.
Common arrays are always variable-length, and must be defined with an empty parameter list (), and its dimensions set in a later Dim or ReDim statement.
Common variables cannot be instances of a user-defined type having a constructor or a destructor even implicit.
The Shared optional parameter makes the variable global so that it can be used inside Subs and Functions, as well as at module level.
I have a DllMain routine where I want to save the dll handle for later use in another module.
Example code bas1.bas :
common shared g_hInst as HINSTANCE ' this is the global variable
Public Function DllMain stdcall Alias "XLLMAIN" _
Byval hDLL As HINSTANCE, _
Byval fdwReason As DWORD, _
Byval lpvReserved As LPVOID _
) As BOOL
Select Case (fdwReason)
' // The instance handle passed into DllMain is saved
' // in the global variable g_hInst for later use.
g_hInst = hDLL 'save hinstance in global variable
common shared g_hInst as HINSTANCE 'declaring as help file says. Correct??
dim szFile1 AS WSTRING* 2048
'g_hInst is global handle of dll. Initiated via DLLMAIN
GetModuleFileNameW g_hInst, @szFile1, SIZEOF (szFile1)
Any hints how to get this going i.e using a global variable over multiple modules.