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[..MAX_PATH] of Char;
begin
FillChar(szFileName, SizeOf(szFileName), #);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
Result := szFileName;
end;

Getting the path of a DLL:

if you call ExtractFilePath(ParamStr(0)) from a DLL you will get the path of the web server, so if you want the path of the DLL itself use:

function ScriptPath: String;
var path: array[..MaxPathLength-] of char;
begin
if IsLibrary then
SetString(Result, path, GetModuleFileName(HInstance, path, SizeOf(path)))
else
Result := ParamStr();
end;

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

  1. C#实现动态调用Windows DLL

    调用方法: object obj = WinDllInvoke("Kernel32.dll", "Beep", , }, typeof(void)); 函数代码 ...

  2. Windows Dll Injection、Process Injection、API Hook、DLL后门/恶意程序入侵技术

    catalogue 1. 引言2. 使用注册表注入DLL3. 使用Windows挂钩来注入DLL4. 使用远程线程来注入DLL5. 使用木马DLL来注入DLL6. 把DLL作为调试器来注入7. 使用c ...

  3. go 调用windows dll 的方法

    go 调用windows dll 的方法 ,代码如下: package main import ( "fmt" "syscall" "time&quo ...

  4. Creating Icon Overlay Handlers / 创建图标标记 Handlers (翻译自MSDN) / VC++, Windows, DLL, ATL, COM

    创建图标标记 Handlers Creating Icon Overlay Handlers 图标标记是放在代表着某个 Shell 对象的图标之左下角的小图像.它们通常被加在一个对象的图标的身上来提供 ...

  5. Windows DLL资料整理

    1.使用Visual C++ 6.0创建dll 2. 函数的调用规则(__cdecl,__stdcall,__fastcall,__pascal) 要点: 1. 如果你的程序中没有涉及可变参数,最好使 ...

  6. windows dll的def文件

    DLL(testcase_1.dll )源码:myfun.h #pragma once #ifdef TESTCASE_1_EXPORTS #define MY_API __declspec(dlle ...

  7. go 调用windows dll 的三种方法

    参考:https://blog.csdn.net/qq_39584315/article/details/81287669 大部分代码参考:https://studygolang.com/articl ...

  8. windows DLL中使用COM的注意事项

    windows的DLL开发是有需要注意的地方的,不然会造成一些问题.由于我最近的使用不当,又造成了问题,虽然之前有写过一篇笔记, http://www.cnblogs.com/foohack/p/66 ...

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

    创建上下文菜单项 1.新建一个ATL Project. 2.建议将Project Property中Linker – General - “Register Output” 设为no,C/C++ - ...

随机推荐

  1. Java Tuple使用实例(转)

    转自链接:http://www.cnblogs.com/davidwang456/p/4514659.html 一.为什么使用元组tuple? 元组和列表list一样,都可能用于数据存储,包含多个数据 ...

  2. 重置HTML标签样式

    ;;} header,footer,section,article,aside,nav,hgroup,address,figure,figcaption,menu,details{display:bl ...

  3. scala学习7--class、object、trait

    scala语言中没有static成员存在,但是scala允许以某种方式去使用static成员这个就是伴生机制,所谓伴生,就是在语言层面上,把static成员和非static成员用不同的表达方式,cla ...

  4. MINIBASE源代码阅读笔记之DB

    DB 管理数据库的类 file_entry:dir page的元素,保存不同文件对应的page directory_page:dir page的专用结构体,里面有个初始长度为0的variable si ...

  5. naive cube implementation in python

    这篇论文中提到的naive cube算法的实现,python写出来真的就和伪代码差不多=.= 输入大约长这样,依次是 index userid country state city topic cat ...

  6. js获取json对象中的key和value,并组成新数组

    //比如有一个json var json = {"name" : "Tom", "age" : 18}; //想分别获取它的key 和 va ...

  7. Java 大小写转换

    Java 大小写转换 public class CaseConversion { /** * @param character: a character * @return: a character ...

  8. 谨防“USB杀手”

    应对来历不明的U盘要小心,因为可能被植入恶意程序或木马,这点相信许多人都知道. 但近两年又出现了一种新的新威胁,下图是一款名为USB Killer的设备,可对电脑硬件造成物理破坏. 它的使用效果很简单 ...

  9. 转:Linux创建进程

    转:http://www.cnblogs.com/GT_Andy/archive/2011/06/21/2086129.html 我们都知道,进程就是正在执行的程序.而在Linux中,可以使用一个进程 ...

  10. Python并发编程-进程间数据共享

    Manager中进程数据不安全 通过加锁解决 from multiprocessing import Manager,Process,Lock def main(dic,lock): lock.acq ...