我试图使这个 C++ 片段的方法适应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