Solved

How to load a Dll subproject into a ActiveX control

Posted on 1998-09-24
27
274 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:dstruve
  • 11
  • 8
  • 6
  • +1
27 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1173605
What do you mean?  Do you mean that you can't debug the function in the DLL?
0
 

Author Comment

by:dstruve
ID: 1173606
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
 
LVL 1

Expert Comment

by:eburley
ID: 1173607
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:jkr
ID: 1173608
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
 

Author Comment

by:dstruve
ID: 1173609
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173610
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
 

Author Comment

by:dstruve
ID: 1173611
Im not really rejecting it but I want to clarify your answer
Why would'nt use the debugger breakpoint?

0
 

Author Comment

by:dstruve
ID: 1173612
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173613
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
 

Author Comment

by:dstruve
ID: 1173614
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
 
LVL 86

Expert Comment

by:jkr
ID: 1173615
OK, to finally clarify it - is it a Windows message hook or not?
0
 
LVL 1

Expert Comment

by:eburley
ID: 1173616
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
 
LVL 86

Expert Comment

by:jkr
ID: 1173617
OK, to finally clarify it - is it a Windows message hook or not?
0
 
LVL 86

Expert Comment

by:jkr
ID: 1173618
OK, to finally clarify it - is it a Windows message hook or not?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1173619
>> 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
 
LVL 86

Expert Comment

by:jkr
ID: 1173620
Ok, sorry for interfering ...
0
 

Author Comment

by:dstruve
ID: 1173621
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
 

Author Comment

by:dstruve
ID: 1173622
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
 

Author Comment

by:dstruve
ID: 1173623
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173624
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
 

Author Comment

by:dstruve
ID: 1173625
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173626
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
 
LVL 86

Accepted Solution

by:
jkr earned 220 total points
ID: 1173627
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
 

Author Comment

by:dstruve
ID: 1173628
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
 
LVL 86

Expert Comment

by:jkr
ID: 1173629
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
 

Author Comment

by:dstruve
ID: 1173630
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
 
LVL 86

Expert Comment

by:jkr
ID: 1173631
Ooops, sorry, mixed the things up (explicitly vs. extrinsically ;-) - not a native english speaker ... (greetings from germany <s>)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question