我用ATL写了一个DLL的组件,是增加系统上下文菜单的。但我想知道在DLL中如何调用一个EXE的函数或功能呢。请指教。谢谢!

解决方案 »

  1.   

    用函数指针。给你的dll添加一个函数SetXXXXFunc(...),其参数是一个函数指针,并将这个指针保存下来。在你的exe启动时,用你要被dll调用的函数做参数调用该函数。dll可以用保存的函数指针调用exe的函数。GetModuleHandle
    The GetModuleHandle function retrieves a module handle for the specified module if the file has been mapped into the address space of the calling process. To avoid the race conditions described in the Res section, use the GetModuleHandleEx function.HMODULE GetModuleHandle(
      LPCTSTR lpModuleName   // module name
    );
    Parameters
    lpModuleName 
    [in] Pointer to a null-terminated string that contains the name of the module (either a .dll or .exe file). If the file name extension is omitted, the default library extension .dll is appended. The file name string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process. 
    If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process. Return Values
    If the function succeeds, the return value is a handle to the specified module.If the function fails, the return value is NULL. To get extended error information, call GetLastError.