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. 配置Tomcat、maven远程部署调试总结。

    注意:可以搞两个环境,一个本地tomcat 一个服务器上的tomcat ,然后都采用如下配置.这样就可以 在本地调试,调试好后,再发布到服务器端.非常方便.  ==================== ...

  2. Jmeter组件和属性(二)

    Jmeter脚本开发原则 简单.正确.高效.简单:去除无关的组件,同时能复用的尽量复用.正确:对脚本或者业务正确性进行必要的判断,不能少也不能多.(200),业务错误的情况下,也可能返回200,必须用 ...

  3. 一张图解AlphaGo原理及弱点

    声明:本文转载自(微信公众号:CKDD),作者郑宇 张钧波,仅作学习收录之用,不做商业目的. 近期AlphaGo在人机围棋比赛中连胜李世石3局,体现了人工智能在围棋领域的突破,作为人工智能领域的工作者 ...

  4. 渗透常用SQL注入语句合集

    1.判断有无注入点; and 1=1 and 1=2 2.猜表一般的表的名称无非是admin adminuser user pass password 等..and 0<>(select ...

  5. js中的for循环

    预定义: var arr=[22,33,12,34];//数组(特殊的对象) var obj={ //对象 name:"Jack", age:"99", sex ...

  6. 783. Minimum Distance Between BST Nodes

    Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...

  7. powerdeginer 默认name 为 common

    在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中写中文,在Code中写英文.Name用来显 示,Code在代码中使用,但Comment中的文字会保 ...

  8. 用js 的for循环打印三角形,提取水仙花数,求本月多少天

    第一题:用for循环打印三角形 //第一个 for(var x = 1;x <= 4;x++){ //控制行数 :由 1 到 4 for(var y = 1;y <= x;y++){ // ...

  9. SQL Join简单介绍

    前沿 Join是关系型数据库系统的重要操作之一,SQL Server中包含的常用Join:内联接.外联接和交叉联接等. 如果我们想在两个或以上的表获取其中从一个表中的行与另一个表中的行匹配的数据,这时 ...

  10. 关于button标签会刷新页面的问题

    当button标签在form表单里面时,这时点击button按钮会提交表单刷新页面. <form action=""> <button>点击</but ...