How to load a Dll subproject into a ActiveX control

I have a ActiveX control Im trying to put a DLL hook into
the workspace.

I am not able to step throught eh dll function although everything compiles correctly.

Daniel
dstruveAsked:
Who is Participating?
 
jkrCommented:
OK, if it is a hook, i'll post what i do to debug it (inside the dll):

// link with .def:
//SECTIONS
//.shared      READ WRITE SHARED

#pragma data_seg( ".shared")
HHOOK      g_hhk =      NULL;
DWORD   g_dwPID = 0;
#pragma data_seg()

// called from process to set the hook
LONG _DYNLINK HookInit  ()
{
    if  (   g_hhk)  return  (   ERROR_ALREADY_EXISTS);

    // store PID of creator process
    g_dwPID =   GetCurrentProcessId ();

    g_hhk   =   SetWindowsHookEx    (   WH_GETMESSAGE,
                                        ( HOOKPROC) HookProc,
                                        g_hThisDll,
                                        0
                                    );
 return ( 0);
}

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

#ifdef __EMIT_BREAKPOINT
    // only break in the process that installed the hook...
    if  (   GetCurrentProcessId ()  ==  g_dwPID)    __asm { int 3};
#endif

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }
//...
}


0
 
nietodCommented:
What do you mean?  Do you mean that you can't debug the function in the DLL?
0
 
dstruveAuthor Commented:
Thanks for answering.  when I step through my ActiveX control method and call the dll function I am not able to step through the  dll project.

the workspace had the ActiveX project and a dll project
Im using the dll project to hook messages from other windows.

Feel free to ask more questions.

Thanks
Daniel
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
eburleyCommented:
do you have a pdb (I'm assuming visual c++) for the dll?  is the dll build to include debug info?  If not, the debugger won't step through it.
0
 
jkrCommented:
I suppose it is a Windows message hook. Well, as you're using a so called 'system wide' message hook, you had to put it into a dll that is mapped into the other processes' address spaces, i.e. the hook executes in the context of the _other_ processes - that's why you can't debug it ... The only way to debug a system wide hook is to emit an '__asm { int 3};' which will cause an EXCEPTION_DEBUG_BREAKPOINT that will bring up the debugger - but be careful! Thil will cause all other processes to stop at this point, too, unless you don't use a method to distinguish between your ActiveX and other processes (e.g. comparing the process' names and conditionally executing the breakpoint)
0
 
dstruveAuthor Commented:
Good answer but yes there is one.
I think that perhaps the dll isnt getting loaded correctly.
Because I include the Dll header in the control class cpp so it find the function declaration but doesnt fine the definition.
need more info?

Daniel
0
 
nietodCommented:
How are you loading the DLL?  it is linked in to you project or are you loading it with LoadLibrary()?
Is the source for the DLL included in the project?  
What compiler are you using?
0
 
dstruveAuthor Commented:
Im not really rejecting it but I want to clarify your answer
Why would'nt use the debugger breakpoint?

0
 
dstruveAuthor Commented:
Im not sure if its linked into the project but I added it using the wizard to make it a subproject to the activex project.
How do I check to make sure its linked?
NO wonder you have so many points. you are diligent!!
0
 
nietodCommented:
I assume this is Microsoft VC, right?  In that case the DLL project should be a sub-project of the activex control project.  Which you say have, but that would be a common cause of this problem, so I want confirm that.  
When the activex code calls the procedure in the DLL, does it use LoadLibrary to load the DLL and then use GetProcAddress() to get a pointer to the function?  or does it just call the function using its name, like "SomeFunction()"

If you use LoadLibrary() and GetProcAddress(), you can place a debugger interrupt  in the function, to get control when the function is entered.  But if you don't use these, I'm not sure what the problem is.

0
 
dstruveAuthor Commented:
Im not sure if its linked into the project but I added it using the wizard to make it a subproject to the activex project.
How do I check to make sure its linked?
NO wonder you have so many points. you are diligent!!
0
 
jkrCommented:
OK, to finally clarify it - is it a Windows message hook or not?
0
 
eburleyCommented:
nietod is correct in specifying the hard coded break point, but even with LoadLibrary/GetProcAddress you can set breakpoints in the visual studio, you just need to add the dll to the "additional dll"'s list in the project/settings/debug tab.
0
 
jkrCommented:
OK, to finally clarify it - is it a Windows message hook or not?
0
 
jkrCommented:
OK, to finally clarify it - is it a Windows message hook or not?
0
 
nietodCommented:
>> How do I check to make sure its linked?
It depends on how you call the function.  Do you just call it like a regular function, ie "somefunction()" or do you use GetProcAddress() to get a pointer to the function and then call the function with the pointer?

>> is it a Windows message hook or not?
No, it is not.

>>you just need to add the dll to the "additional dll"'s list in the project/settings/debug
I forgot about that!  Due to unusual circumstances in my project, I can't do it that way anymore.
0
 
jkrCommented:
Ok, sorry for interfering ...
0
 
dstruveAuthor Commented:
The dll is a message hook but has a function to call an HOOKPROC.
I call the dll function from the activex class .
I am calling the funciton in the dll like a reagular function since I implicitly linked using including the dll header in the control class cpp.
0
 
dstruveAuthor Commented:
The dll is a message hook but has a function to call an HOOKPROC.
I call the dll function from the activex class .
I am calling the funciton in the dll like a reagular function since I implicitly linked using including the dll header in the control class cpp.
0
 
dstruveAuthor Commented:
The dll is a message hook but has a function to call an HOOKPROC.
I call the dll function from the activex class .
I am calling the funciton in the dll like a reagular function since I implicitly linked using including the dll header in the control class cpp.
0
 
nietodCommented:
Opps, jrk, you were right!  (I hope you're still here.)

dstruve, what function are you trying to debug?  Are you trying to debug a function that calls installs the window hook using SetWindowsHook(), or are you trying to debug the hook callback function that SetWindowsHook() is supposed to call?  

Can you post your code?  That would help a lot.
0
 
dstruveAuthor Commented:
Looks, like my comments got carried away.

the setwindowshook get called inside the dll.
I call the dll from the activex control.
I am under the understanding that you cannot debug the winproc. handler.
0
 
nietodCommented:
Please read our questions carefully.  

What is the function that you can't debug?  Is it the function that calls SetWindowsHook(), or is it the callback function that is called by SetWindowsHook()?

I'm not sure what you are saying about the winproc.  But you can debug a window procedure.  (I do all the time).

It might help if you would post some of your code.  You can just copy and paste it right in.
0
 
dstruveAuthor Commented:
jkr, that is very creative. I like that.
Sorry for the delay, had to take off for the weekend.
I have recently found out that Im not even linking to the darn DLL.  I have been successful  explicitly though. I just wanted to be able to do it implicitly(call the dll thru my OCX) I got the link2001 error and I stepped through the long list of possiblities but to no avail.

Thanks for you reply.

Daniel
0
 
jkrCommented:
If you want to implicitly use _functions_ in a DLL, use code like this:

typedef      int ( *PUSRLCK) ( char*);

//...

HANDLE      g_hUserLockDll      =      INVALID_HANDLE_VALUE;
PUSRLCK      g_pfnUserLock      =      NULL;

//...

    g_hUserLockDll  =   LoadLibrary (   g_acUserLockDll);

    if  (   !g_hUserLockDll)
        {
            g_hUserLockDll  =   INVALID_HANDLE_VALUE;

            return  (   FALSE);
        }

    g_pfnUserLock   =   ( PUSRLCK)  GetProcAddress  (   g_hUserLockDll,
                                                        g_acUserLockProc
                                                    );

    if  (   !g_pfnUserLock)
        {
            return  (   FALSE);
        }

    if  (   ! ( *g_pfnUserLock) (   "test"))    return  (   FALSE);

NOTE that you'll have to take care that the functions are exported without C++ name mangling, so the best thing is to list them in a .def file used with your project.

If you want to use _methods_, the things are more complicated...

(BTW: Are you german? The name sounds like you are ;-)
0
 
dstruveAuthor Commented:
Thanks, but I thought using Loadlibrary was explicit???


Yes, 4th or 5th generation Texan immigrated from Germany in 1800s to land at Galveston. Struve
I live in Houston.
0
 
jkrCommented:
Ooops, sorry, mixed the things up (explicitly vs. extrinsically ;-) - not a native english speaker ... (greetings from germany <s>)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.