开发者

VB importing of DLL functions with build type conditionals

开发者 https://www.devze.com 2023-03-19 05:36 出处:网络
So I\'m trying to import a function from a library I\'m developing. I have \"libraryD.dll\" built for debugging and \"library.dll\" for release. Unfortunately, that means that I have to do this:

So I'm trying to import a function from a library I'm developing. I have "libraryD.dll" built for debugging and "library.dll" for release. Unfortunately, that means that I have to do this:

#If Debug
Declare Function someFunction Lib "library.dll" Alias "someFunc" () As Integer
#Else
Declare Function someFunct开发者_如何学编程ion Lib "libraryD.dll" Alias "someFunc" () As Integer
#EndIf

Now this would be fine but for ALL 40 functions this would make things very ugly to look at (and a tad bit unfriendly).I would like to do something more like this:

#If Debug
#Const dllName = "libraryD.dll"
#Else
#Const dllName = "library.dll"
#EndIf
Declare Function someFunction Lib dllName Alias "someFunc" () As Integer

Is there ANY way to do this in VB? :-(

TIA!


You simply do one thing...

    Dim dllName as string
    #If Debug
    dllName = "libraryD.dll"
    #Else
    dllName = "library.dll"

    Declare Function someFunction Lib dllName Alias "someFunc" () As Integer

This will certainly solve your problem...
Happy coding... :)


Try using the DLLImport attribute:

#If Debug
 Const dllName = "libraryD.dll"
#Else
 Const dllName = "library.dll"
#EndIf

    <System.Runtime.InteropServices.DllImport(dllName)> Private Shared Function somefunction() As Integer
    End Function
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号