Home » C++ Programming


i am creating global hooking for mouse and keyboard in vc++ and vb6.And in vc++ dll i want to open the text file when the dll is loaded first time in the memory and want to close that text file when the dll is unloaded.how to code dll for this purpose?plz reply any idea about that fast.

7 Answers Found


Answer 1

global  hook DLL has to be hosted by an EXE that calls (Set|Unhook)WindowsHookEx, so do it in the EXE.



Answer 2

i am creating  global hooking  for mouse  and keyboard  in vc++ and vb6.And in vc++ dll  i want to open  the text  file when the dll is loaded  first time  in the memory  and want to close  that text file  when the dll is unloaded.how to code  dll for this purpose?plz  reply  any idea  about that fast.

I do not quite understand why you need to use hooks.

Each DLL has an entry point or initialization function; for example Win32 DLL has DllMain and one of parameters is a reason to call. On loading (DLL_PROCESS_ATTACH) open file and close it when DLL is unloaded  (DLL_PROCESS_DETACH).

You can also implement two exported functions that can be called from any module to maintain file stream.


Answer 3

Doug, I respectfully disagree.

All (but two) windows hooks that are to be global must have hook procedure in a DLL; hence it easier to also set hook in a DLL. However it is also possible to set hook in an executable module enquiring module handle of a dll  that contains hook procedure. It is more complicated though since dll would have to export it.


Only two hooks can be initiated by passing hook procedure located in an executable module: WH_MOUSE_LL and WH_KEYBOARD_LL.


Answer 4

I was not saying that the hook procedure should exist in the EXE. (I was not aware that was even possible.)

I was saying that that DLL that hosts the hook must be loaded  by an EXE to become established, and since that EXE is the first thing to load the hook DLL, it would seem to meet the OP's requirements.


Answer 5

Sorry I misunderstood your post.

As I have mentioned, two hooks are global  and they can be set in an exe module.

Also any hook that is not global can be set in an exe module. The difference is that instead passing module handle hook is set by passing thread ID.

I am still not sure why OP needs a hook.


Answer 6

LRESULT CALLBACK _stdcall MouseJi(int code,WPARAM w,LPARAM l)
                                            MSLLHOOKSTRUCT *m=(MSLLHOOKSTRUCT *)l;
                                            ofstream fout("D:\\a.txt",ios::app);
                        return CallNextHookEx(ms,code,w,l);

But setwindowshookex() will be in vb6  code.

so my problem is each time mouse  event occurs and file  will be opened/closed and all.

and if  i open  the file in dll_process_attach,it will be opened/closed each time  the new process is attached/deattached to the dll.

but i want to do it only once when dll  loads/unloads.how?


Answer 7

xxxyyyzzz123 wrote:

*LRESULT CALLBACK _stdcall MouseJi(int code,WPARAM w,LPARAM l)
ofstream fout("D:\\a.txt",ios::app);
return CallNextHookEx(ms,code,w,l);

and if i open  the file  in dll_process_attach,it will be opened/closed  each time  the new process is attached/deattached to the

*but i want to do it only once when dll  loads/unloads.how?

"Process attached to a DLL" is just another way of saying "the DLL was  loaded  into a process". File streams cannot be shared across processes,  so each instance of the DLL in every process would need to open its own.

Igor Tandetnik

Search for  DLL

Quick background - I'm working with a medium-sized 64-bit FEA code and am having trouble getting it to work on a new machine (running Server 2008) we just got.  It builds with Visual Studio 2008 on the machine but whenever I try to run the exe, it fails to run, printing the following to the command prompt: "the application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail."

So, I fired up Dependency Walker and it appears the application cannot find MSVCP90.dll, MSVCR90.dll, or VCOMP90.dll.

I checked on my 64bit Vista workstation (where the exe does work) with Dependency Walker and on my machine, the exe knows where the dlls are (c:\windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\MSVCP90.DLL, for instance).  The thing that strikes me as slightly weird is that this location is not in my path, thus the following questions:

   1. How does the .exe file on the computer where the program works know where to find .dll files that aren't in the path of the machine its being run on?
   2. Why can't the executable on the other machine find the .dll files?

A few other things to note:
The .dll files that need to be linked at runtime exist on the other machine, and at the same path (I assume for all of them, I checked MSVCP90.DLL and it existed, in exactly the location, for both machines)
When I copy the .exe file from the machine that works correctly to the machine where it doesn't work correctly, I get the same error (in other words, it appears that the exe itself doesn't store the location of the dll file).  Dependany Walker shows that on the Server 2008 machine (where the exe doesn't work), the exe can't find the .dll files.
On both machines I am developing with Visual Studio 2008.

Thanks for any help you can provide.



I am trying to fix a client's problem with one of my company's products.  One of the dll's won't register there, but works here (isn't always the case).  I had them do a dependency walker check and it states that msvcr80.dll cannot be found under the WinSxS mfc80.dll branch.  However the very next branch has the WinSxS msvcr80.dll loading fine.

     - msvcr80.dll (dependency not found)
     - (other dlls)
winsxs\*4053*\msvcr80.dll  (this branch has no errors)

I don't understand why it produces a dependency not found when in fact it has it in another branch.

Any suggestions?


I am using VS 2008, Team Ed.

I have a solution that has a C++ project that builds a DLL and copies it to the other projects relevant debug directory (so that it auto-links). 

There is then a C# project that calls a function within the C++ DLL.  This works (it took awhile).

However, when I set break-points in the C++ project, they do not work at all.

The C# break-points do work.

As far as I know, all projects are set to "DEBUG" and using the DLL for the DEBUG build.


Anyone have any ideas?


This is all within the VS2008 IDE.


P.S. Is this a problem that VS 2010 addresses specifically???




As, we are going to create AddIn for Outlook 2007/2003)

I have created a sample piece of code application with Visual Studio 2005( without wring outlook add-in code).

Project-1 is with "Class Library" type

- include all the code UCCAPI to create platform and session)
- include all 3 dlls which has been informed by help of UCC API coding also set - Copy Always to Output dir.
- Add Reference of Interop.
- Write a manifest "Project1.dll.manifest" and include in project (as per the Help file of UccApi.Dll)

Project-2 is with "WindowsApplication" depends on Project-1

- Calling  Project- 1 Assembly's Wrapper class which create PlatformClass object.

When I execute the code Getting following error- 

Retrieving the COM class factory for component with CLSID {EC10E7E8-797E-4495-A86D-3E9EADA6D5BB} failed due to the following error: 80040154.

Now, If I register UccApi.Dll using regsvr32

The project will execute success-fully , But my UCCAPI.dll has been exposed globally and it is no more private.

I alos did one test, where I copy everything in Project-2 (which is and application executable).

and did the same above steps. It worked fine. without REGISTERING the COM dll.

My Questions are?

1) Is it compulsory to Register UCCAPI.dll? If No, How can I make it private only with only DLL.Manifest

3) Why exe.Manifest is able to load COM DLL and why not dll.manifest?

2) Please send me the sample code to load UccApi.dll throgh assembly manifest only (means - <project>.dll.manifest - Not exe.manifest)

Please let me know if any thing else is required.

After installing Gemini, I ran Excel 2010 and get this error message:

Name: Microsoft.AnalysisServices.Modeler.FieldList - Microsoft.AnalysisServices.Modeler.FieldList
From: file:///C:/Program Files/Microsoft Analysis Services/AS Excel Client/10/Microsoft.AnalysisServices.Modeler.FieldList.vsto

************** Exception Text **************
System.EntryPointNotFoundException: Unable to find an entry point named 'MsoFRequireSignedAddins' in DLL 'mso.dll'.
at Microsoft.VisualStudio.Tools.Office.Runtime.NativeMethods.MsoFRequireSignedAddinsamd64()
at Microsoft.VisualStudio.Tools.Office.Runtime.NativeMethods.MsoFRequireSignedAddins()
at Microsoft.VisualStudio.Tools.Office.Runtime.OfficeAddInDeploymentManager.VerifyAddInTrust(ClickOnceAddInTrustEvidence evidence)
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySecurity(ActivationContext context, Uri manifest, AddInInstallationStatus installState)
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()

I try to add ''C:\Program Files\Microsoft Analysis Services\AS Excel Client" to the trusted location (subfolders included) . But nothing change.

If I try to execute the vsto, I get this error message:
System.Deployment.Application.DeploymentDownloadException: Downloading file:///C:/Program Files/Microsoft Analysis Services/AS Excel Client/10/makefile.inc did not succeed. ---> System.Net.WebException: Could not find file 'C:\Program Files\Microsoft Analysis Services\AS Excel Client\10\makefile.inc'. ---> System.Net.WebException: Could not find file 'C:\Program Files\Microsoft Analysis Services\AS Excel Client\10\makefile.inc'.
I have a precreated .net Dll. This dll does not have Classes that are COM callable would I be able to create a reverse interop? i mean is there a possibility to convert a already existing .net dll to COM dll?
i got his message after today update. I'm relieved that it is not just my com but rather the update. Anyone knows how to solve this problem?
My com seems to hang v often after i got the message.
Microsoft should fix the bug quickly.

while building a program, then press VS2010 Unable to load DLL 'FileTracker.dll' when I look back on all my machines Forum implementation missing file C: \ Windows \ Microsoft.NET \ Framework \ v4.0.21006 \ File Tracker. dll, which can lead v4 0. V4 30 128 and .0.30319. Should not my chapter vtrinh construction. expect people to help

We have created a project that compiles, links, and executes just fine.  However, when I build, Microsoft.Office.Interop.Excel.dll and office.dll appear in my bin directory.  There are no references to either of these in our application, and if I delete them from my bin directory the application runs just fine.

I have Visual Studio 2008 and Office 2003 on my PC.

When my colleague builds, these two libraries do not appear in the bin directory.

He has Visual Studio 2008 and Office 2007 on his PC.

Can someone help me figure out what is causing my PC to include these unnecessary DLLs?


A Environment: Vista VB32 US , Visual Studio 2008 ,.Net 3.0

B Step: .
   Create a VC.Net project-> add a class on project, select ATL Simple Object,Default selection ->click Finish

C Problem:
  once you click Finish, It will alert "c:\Net3\v6.0\bin\rcdll.dll; c:\MSV9\vc\bin\rdll.dll Cannot find the resource compiler DLL. Plse make sure the path is correct."
D Explanation:
  c:\Net3 is where i installed .Net3.0 , c:\MSV9 is where i installed Visual Studio 2008
E What i tried:
   When I find rcdll.dll at c:\winddk\xxxx wherei have installed WinDDK, i copied rcdll.dll(x86)  to c:\MSV9\VC\bin . Then i tried to add ATL Simple Object,
   If i click Finish , it will give a lot of paths , i don't know what it want to clarify.


Hi friends,


I am trying to convert pdf file to imagefiles for that i am using dll solidframe work but i am getting the exception  "Unable to load DLL 'Framework.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)".


How to add framework dll


thanks in advance.


I have inherited a ATL VC++ project that was originally developed in Visual Studio 2003.  I have been tasked with getting the project to compile within Visual Studio 2010.  I have fixed lots of little problems like identifiers being out of scope, etc., but I seem to have one last hurdle to overcome.  I have successfully compiled and linked the project, but when it tries to register the DLL, regsvr32 fails.  I opened up the dll in the depenency walker, and I'm missing out on GPSVC.dll and IESHIMS.dll.

I've done a few searches, and it appears I'm not the only one having this problem, although I can't find any good solutions.  I need to know if there is anything I can do to get this thing to compile.  I'm running Windows 7 64-bit, but I've specified win32 as the target platform.  I'll need this project to be deployed on Windows 2003 Server.  I have some experience with VC++, but it's been a while.  If anyone has some relatively simple ideas on what I can do, I would really appreciate it.



Ok listen up.

Ive got a dll which is in the GAC which i connect to remotely.

In this dll, I have a reference to a 3rd party dll (Firebird) which is on the local disk.

now i havent put this dll in the GAC yet since its not ready, but i heard there might be some restrictions.

Is this so? if so, what are they and what alternative do i have?




Hi All,

I am trying to connect to an iSeries database using .NET. The server I am trying to connect from is a 64 bit Windows Server 2008 machine. I have iSeries Access v5r4 installed and a DSN entry(64 bit ODBC) created with the iSeries Access ODBC Driver. In my C# class, the connection and data retrieval works fine if I use OdbcConnection and OdbcCommand. But if I try and use IBM.Data.DB2.iSeries.iDB2Connection then I get the error - Unable to find an entry point named '#507' in DLL 'CWBDC.dll' error. I have referenced IBM.Data.DB2.iSeries.dll in my project. Anyone run into this issue before? I found a couple more people who asked this question when I did a google search but there were no answers listed. Any help would be appreciated.




I can't include Microsoft.Maps.MapControl.dll and
Microsoft.Maps.MapControl.Common.dll in the installer of
the package softwareware?

 Right to Use and Distribute. The code and text files
 listed below are “Distributable Code.”
 ·Sample Code. You may modify, copy, and distribute
   the source and object code form of code marked as
But It is not written as a "sample" in Microsoft.Maps.MapControl.dll
and Microsoft.Maps.MapControl.Common.dll




I have a mixed C++/CLI dll and a managed C# class library dll. I need to call the C# managed dll from the C++ mixed dll.

The mixed dll is actually a Firefox plugin, this construct was made to be able to call the C# dll from javascript on a Firefox extension. I know I could do this using COM interop but that's something I want to avoid, for starters, you have to register the C# dll and this is a deployment problem I don't want to have later.

Ok. I have a something that compiles and works, until the C++ code tries to call a method from the wrapper class that encapsulates calls to C# code, on that very moment I get a FileNotFoundException telling me that it can't find the C# dll (called Common.dll). That dll is copied in the same folder than the C++ dll, a Firefox folder for plugins.

I get this error both executing normally and debugging.

For now, I'm trying to call a static method of a static class. The C# code looks like this:



publicstaticclass Data<br/>
  privateconststring CURRENT_VERSION = "0.1";<br/>
  publicstaticstring GetEmptyData()<br/>
    return"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<DataRoot xmlns=\"http://tempuri.org/DataDef.xsd\" DataVersion=\"0.1\" RelatedText=\"\"></DataRoot>";<br/>

As you can see, it's just a method that returns a string.

The C++ wrapper code is this (header file):

class __declspec(dllexport) DataWrapper

  staticvoid GetEmptyData(LPSTR sData);

And the cpp file:

#include "StdAfx.h"
#include "DataWrapper.h"

#include <msclr/marshal.h>
usingnamespace msclr::interop;

#include <strsafe.h>

usingnamespace System;
usingnamespace System::Runtime::InteropServices;
usingnamespace Common;




void DataWrapper::GetEmptyData(LPSTR sData)
  String ^ str;
  str = Common::Data::GetEmptyData();

  // Convert System::String to PCWSTR.
  marshal_context ^ context = gcnew marshal_context();
  PCSTR pszStr = context->marshal_as<constchar*>(str);
  DWORD dwSize = lstrlenA(pszStr) + 1;
  HRESULT hr = StringCchCopyA(sData, dwSize, pszStr == NULL ? "" : pszStr);
  delete context; // This will also free the memory pointed by pszStr

On another cpp file, there's a method Firefox calls when the javascript tries to call a function from your plugin. I have a test.html file with a button that does just that. This function starts like this:

bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)<br/>
 if (name == sFoo_id)<br/>
  //Creates and shows a MessageBox<br/>
  MessageBoxA(NULL, "Hello! I'm the C++ program", "MyPlugin", MB_OK);<br/>
  //Calls a Javascript alert (in browser)<br/>
  NPObject* window;<br/>
  if (NPN_GetValue(m_pNpp, NPNVWindowNPObject, &window) != NPERR_NO_ERROR)<br/>
    MessageBoxA(NULL, "Error getting window object", "MyPlugin", MB_OK);<br/>
  NPVariant message;<br/>
  char sMsg[65536];<br/>

This method is getting called because I put a breakpoint on "XtyleDataWrapper::GetEmptyData(sMsg);" and the execution stops there when I'm debugging. I get the FileNotFoundException just afterwards, when the C++ dll tries to call the method.

As I've said, the C# dll is copied in the same folder than the C++ dll.

I can see the first MessageBox too.

What am I missing here?



-Sergi Díaz

Exception:"Can't find PInvoke DLL 'sqlceme35.dll"

When I run the application in emulator the above exception message is shown.

should I install any SQL Server Compact in the device or emulator?
If Yes,please provide the links for for the setup files.




Upgrading my VC++ solution from 2008 to 2010 using Professional.  I get unresolved external symbol errors for 2 functions.  I used dumpbin /exports to determine that msvcr9.dll held these functions.  The msvcr100.dll does not anymore and I'm trying to figure out where they moved.

I have a COTS C library and .h that have dependencies on these.  I don't own the source code to rewrite or rebuild.




I need a help for following problem:

I have set of applications organized in some directory structure say


C:/Product/B/bin/program_1.exe <dependent on python26.dll and zlib.dll>
C:/Product/C/bin/program_2.exe <dependent on python26.dll and zlib.dll>

Sometimes, these python26.dll and zlib.dll are found in C:/WinNt/system32 directory for some reason, so our dlls are not picked up even we have C:/Product/A/bin/ directory in the PATH environment.

Reason behind this is the Windows dll search order (which first search in the same directory where application resides, followed by System folders, and then PATH environment variable).

Is there a way to write an application manifest file which can instruct that dll should be picked up from C:/Product/A/bin directory before looking into System folders?

If yes, then what should be the content of manifest file for above situation for example?

Any help would be appreciated in this regard?



I have adapted instructions in the following thread for my own application:


I have two dlls that I want to specify in an assembly and load in my application. The two dll's are:

boost_python-vc90-mt-1_43.dll boost_python-vc90-mt-gd-1_43.dll

I created file boost_python.assembly.manifest with the following contents: 


Then, I added the following to a .cpp file of my application:

#pragma comment(linker,"/manifestdependency:\"type='win32' "\

"name='boost_python.assembly' "\

"version='' "\

"processorArchitecture='*' "\

"language='*' "\


 Then I put the dll's and the manifest in the same folder as the application executable and ran it. I then get error:

'The application has failed to start because the application configuration is incorrect.'

I am developing under Visual C++ 2008 Express on Win XP SP3.

Please can anyone suggest what is wrong with what I have done?

Best regards


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure