Results 1 to 5 of 5

Thread: public variables and dlls

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    36

    public variables and dlls

    Hi guys. I'm new to this forum.

    I have noticed this behaviour in a vb6 app of mine :

    i have a public variable let's call it Number and two buttons cmd1, cmd2. cmd1 calls a function from a custom .dll of mine and also assigns a value to Number variable. If i then press cmd2 button i display a message with Number value. The issue is that it always displays 0 as if Number variable was not public but local. If in cmd1 i don't call the .dll function there is no such weird behaviour.

    code :

    Code:
    Option Explicit
    
    Public Number As Integer
    Private Declare Function DllMain2 Lib "G:\1\testdll.dll" () As Boolean
    
    Public Sub Command1_Click()
        
        Dim bb As Boolean
            
        bb = DllMain2
        Number = 5
        
    End Sub
    
    Public Sub Command3_Click()
    
        MsgBox (Number)
    
    End Sub
    so i press command1, then command2 button it the messagebox always displays 0 unless i don't call dllmain2 function. thank you in advance for your help

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: public variables and dlls

    If you put a MsgBox instead of Number = 5 (right after the DLL call), is it shown?
    Do you perform any Error handling in the real sub/Function that calls the DLL? In this case an error that pops out would go directly to the handler ignoring the code after the call.
    Last edited by jcis; Apr 6th, 2009 at 02:38 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    36

    Re: public variables and dlls

    hm actually no. if i put a messagebox right after the calling of the dll function it does NOT appear. it appears ONLY after i close my app.
    the function of the .dll does a while loop which gets windows messages

    Code:
    bool TESTDLL_API DllMain2()
    {
    	MSG          msg;             // A Win32 message structure.
    
    	int HotKeyID = 100;
    	HWND hWndExtern;
    	LPDWORD procExtern=NULL;
    	DWORD hThreadExtern;
    
            /// Disable Alt-Tab - Start
    	BOOL m_isKeyRegistered1 = RegisterHotKey((HWND)vbWindowHandle, HotKeyID, MOD_ALT, VK_TAB);
    	/// Disable Alt-Tab - End
    
    	while (GetMessage (&msg, (HWND)vbWindowHandle, 0, 0))
        {
    		if ( msg.hwnd == 0 ) break;
    		
    		// Kill Task Manager - Start
    		hWndExtern = FindWindow(NULL,"Windows Task Manager");
    		if (hWndExtern) {
    			hThreadExtern = GetWindowThreadProcessId(hWndExtern, procExtern);
    			if (hThreadExtern) {
    					PostThreadMessage((DWORD)hThreadExtern, (UINT)WM_QUIT, 0, 0);
    			}
    		}
    		// Kill Task Manager - End
    
    		TranslateMessage (&msg); 
    		//if ( msg.message != WM_HOTKEY ) {
    			if ( msg.message == WM_INPUT ) {
    				keybhnd = 0;
    				//wsprintf(printmessage, "vbWindowHandle : %u\n", msg.wParam);
    				//MessageBox(NULL, printmessage, "msg", MB_OK);
    				MainWndProc2(msg.hwnd, msg.message, msg.wParam, msg.lParam);
    			}
    			DispatchMessage (&msg);
    		//}
        }
    
        return true;
    }

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: public variables and dlls

    It looks like execution gets to line bb = DllMain2 and for some reason it never returns from that DLL. It's weird that events keep working in this Window (you said you clicked Command3 and the MsbBox shows 0), because VB6 is single-threaded, there is only one thread running and it's waiting for answer from the DLL. I'm not sure what could be happening here.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    36

    Re: public variables and dlls

    hm i think that because of the while(GetMessage) loop which continues as long as the loop receives windows messages, the function DllMain2 doesn't return anything as it is still running. it only returns when the vb6 app terminates. yes all other events keep going and i can handle low lvl input

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width