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
Syntax
I have a DllMain routine where I want to save the dll handle for later use in another module.Common [Shared] symbolname[()] [AS DataType] [, ...]
Description
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.
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)
Case DLL_PROCESS_ATTACH
' // 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
Case DLL_PROCESS_DETACH
Case DLL_THREAD_ATTACH
Case DLL_THREAD_DETACH
End Select
Return 1
End Function
Bas2.bas
common shared g_hInst as HINSTANCE 'declaring as help file says. Correct??
Sub Get_PATH()
dim szFile1 AS WSTRING* 2048
'g_hInst is global handle of dll. Initiated via DLLMAIN
GetModuleFileNameW g_hInst, @szFile1, SIZEOF (szFile1)
end sub
Any hints how to get this going i.e using a global variable over multiple modules.
\E