Solved

How to load a Dll subproject into a ActiveX control

Posted on 1998-09-24
27
270 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now