【问题标题】:How can I get the current filename in a FreeBasic DLL?如何获取 FreeBasic DLL 中的当前文件名?
【发布时间】:2017-04-30 05:01:35
【问题描述】:

如何让 FreeBASIC DLL 找到自己的文件名和路径? 到目前为止,我已经尝试过:(使用 rundll32 文件名,DllMain 运行它) 代码:

#include "windows.bi"
Extern "Windows-MS"
Sub DllMain() Export
    dim This as String
    This = dir(command$(0))
    MessageBox( null, "Hello World", This, MB_OK )
End Sub
End Extern

。 . .但它不起作用。

当我将它编译为 EXE 时,它工作正常。

有什么建议吗?谢谢!

【问题讨论】:

    标签: dll freebasic


    【解决方案1】:

    我尝试将approach of this C++ snippet 调整为 FreeBASIC。乍一看,它似乎有效。但是:片段“按原样”提供,不提供任何形式的保证。使用风险自负。

    #include "windows.bi"
    
    Const GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = &H2
    Const GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = &H4
    
    Extern "Windows-MS"
    
    Function getMyPath() As String
        ' See https://stackoverflow.com/a/6924332/ 
        Dim path As ZString * 255
        Dim hm As HMODULE = NULL
        If GetModuleHandleEx( _
                GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS Or _ 
                GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, _
                Cast(LPCSTR, @getMyPath), _
                @hm _ 
            ) Then
                GetModuleFileName( hm, path, SizeOf( path ) )
        End If
        Return path
    End Function
    
    Sub DllMain() Export
        dim dllPath as String
        dllPath = getMyPath()
        MessageBox( null, dllPath, "Hello World", MB_OK )
    End Sub
    
    End Extern
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多