Can a windows dll retrieve its own filename?

http://stackoverflow.com/questions/2043/can-a-windows-dll-retrieve-its-own-filename

A windows exe file has access to the command string which invoked it, including its path and filename. eg.

C:\MyApp\MyApp.exe --help.

But this is not so for a dll invoked via LoadLibrary. Does anyone know of a way for a dll to find out what its path and filename is?

Specifically I‘m interested in a Delphi solution, but I suspect that the answer would be pretty much the same for any language.

I think you‘re looking for GetModuleFileName.

{
  If you are working on a DLL and are interested in the filename of the
  DLL rather than the filename of the application, then you can use this function:
}

function GetModuleName: string;
var
  szFileName: array[0..MAX_PATH] of Char;
begin
  FillChar(szFileName, SizeOf(szFileName), #0);
  GetModuleFileName(hInstance, szFileName, MAX_PATH);
  Result := szFileName;
end;
时间: 2025-01-11 02:19:51

Can a windows dll retrieve its own filename?的相关文章

windows dll

dumpbin的用法为:dumpbin  /exports  my.dll  >  my.def dlltool的用法为:dlltool  -D  my.dll  -d  my.def  -l  my.lib  //生成 .lib 文件          或者为:dlltool  -D  my.dll  -d  my.def  -l  my.a    // 生成 .a 文件 windows dll

Windows Dll Injection、Process Injection、API Hook

catalogue 1. 引言 2. 使用注册表注入DLL 3. 使用Windows挂钩来注入DLL 4. 使用远程线程来注入DLL 5. 使用木马DLL来注入DLL 6. 把DLL作为调试器来注入 7. 使用createprocess来注入代码 8. api拦截 9. Detours - Inline Hook 1.  引言 应用程序需要跨越进程边界来访问另一个进程的地址空间的情况如下 1. 我们想要从另一个进程创建的窗口派生子类窗口 2. 我们需要一些手段来辅助调试,例如我们需要确定另一个进

Creating Context Menu / 创建上下文菜单项 / Win32, VC++, Windows, DLL, ATL, COM

创建上下文菜单项 1.新建一个ATL Project. 2.建议将Project Property中Linker – General - “Register Output” 设为no,C/C++ - “Code Generation” - “Runtime Library” 设为 /MTd. 3.在Solution Explorer中右键Add Class,选择ATL Simple Object.并在弹出的对话框中为该Class命名. 4.添加完成后建议Build一下Project,MIDL c

Golang通过syscall调用windows dll方法

本用例在GO 1.4.2 上编译执行通过,直接上CODE: package main import (     "fmt"     "syscall"     "time"     "unsafe" ) const (     MB_OK                = 0x00000000     MB_OKCANCEL          = 0x00000001     MB_ABORTRETRYIGNORE  = 0x

go 调用windows dll 的三种方法

参考:https://blog.csdn.net/qq_39584315/article/details/81287669 大部分代码参考:https://studygolang.com/articles/2712 第三种方法是从Go\src\internal\syscall\windows\sysdll源码中找到的,三种方法的具体区别还不是很明晰, 初步判断:lazy应该是相当于动态库,其余两种直接把库加载到内存. package main import ( "fmt" "

Windows dll注入

概念 DLL注入(英语:DLL injection)是一种计算机编程技术,它可以强行使另一个进程加载一个动态链接库以在其地址空间内运行指定代码[1].在Windows操作系统上,每个进程都有独立的进程空间,即一个进程是无法直接操作另一个进程的数据的(事实上,不仅Windows,许多操作系统也是如此).但是DLL注入是用一种不直接的方式,来实现操作其他进程的数据.假设我们有一个DLL文件,里面有操作目标进程数据的程序代码逻辑,DLL注入就是使目标进程加载这个DLL,加载后,这个DLL就成为目标进程

windows 操作系统下git报filename too long 处理方法

两种方法解决: 一是通过修改配置文件 [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true longpaths = true 二是通过命令修改,本质是一样的: # 在git bash中,运行下列命令: git config --global core.longpaths true ++++++++++++

Windows API参考大全新编

书名:新编Windows API参考大全 作者:本书编写组 页数:981页 开数:16开 字数:2392千字 出版日期:2000年4月第二次印刷 出版社:电子工业出版社 书号:ISBN 7-5053-5777-8 定价:98.00元 内容简介 作为Microsoft 32位平台的应用程序编程接口,Win32 API是从事Windows应用程序开发所必备的.本书首先对Win32 API函数做完整的概述:然后收录五大类函数:窗口管理.图形设备接口.系统服务.国际特性以及网络服务:在附录部分,讲解如何

calling c++ from golang with swig--windows dll 二

Name mangling && Name demangling 在讲述golang如何利用swig调用windows dll之前,需要了解一个概念:Name Mangling (或者叫Decorated Name).在百度翻译中输入Name Mangling,翻译成中文是“名字改编”,或者“名称重整”.Decorated Name,是微软的叫法,被百度翻译为“修饰名”.不管是英文名,还是翻译后的结果看,Name Mangling的叫法是比较合适的,并且是C++领域内的普遍叫法.通常情况下