Hi everyone.
I use an external DLL and I want inlay the DLL into my exe program. (I don't want copy the exe program and the dll file, just 1 file!)
How can I do that and I can call the dll file in the code
Hi everyone.
I use an external DLL and I want inlay the DLL into my exe program. (I don't want copy the exe program and the dll file, just 1 file!)
How can I do that and I can call the dll file in the code
include DLL widthout make reference....
Lord Foul
can you give me another shot
Sorry, I'm newer on this !!!
allen5928
Sure! Lets try a sequence of events approach. On the left I have MyApplication.exe and on the right I have MyExternalDependency.dll.
1. First I just need to add MyExternalDependency.dll as a reference to the MyApplication.exe project. This is no different from adding any other dependency.
2. I need to then right-click on the project (in the visual studio IDE) and select "add" and then "add existing item". Browse to the location of MyExternalDependency.dll and add it to your project directly.
3. After you've added MyExternalDependency.dll to your project as a file, select it and look at the property grid on the right. Select the property labelled "Build Action" and change it's value to "Embedded Resource"
4. Now...when you fire up MyApplication.exe it knows it has a dependency called MyExternalDependency.dl. In a normal scenario it first looks in the directory within which it is currently executing to "resolve" (find) the dependency. If it doesn't find it there it uses something called "probing" to look in all of the subfolders of the directory within which MyApplication.exe is executing to see if it can find MyExternalDependency.dll there. Finally, if it still doesn't find it, it goes out and looks in the Global Assembly Cache to see if it is there. This is where the code I pointed you to comes into play. This code hooks into the process and tells MyApplication.exe that it can find MyExternalDependency.dll embedded within the executing application. This means when you go to declare it, how you're loading it doesn't matter. You still just declare it like you would any other dependency you're loading and not trying to embed. Lets say MyExternalDependency.dll had a class called "TestClass" and a method called "TestMethod", declaring it would look something like:
Dim ExternalTestClass as new MyExternalDependency.TestClass
ExternalTestClass.TestMethod
Does that make a little more sense
Christopher
duke_
This guy has a great example of how this is done. The route I was going would have required dynamically invoking the methods. With his you can actually reference the dependency ahead of time and point the executable in the right direction for resolving the referenced assembly's location.
http://objecthead.blogspot.com/
Christopher
ragintiger
You could try to start with, for example:
Dim DLL As Assembly
Dim b() As Byte
b = My.Resources.PluginTest_dll
DLL = Assembly.Load(b)
Debug.WriteLine(DLL.GetName)
Dim t As Type
For Each t In DLL.GetTypes
Debug.WriteLine(t.Name)
Next
Then use various reflection calls to get the method you want, parameters, etc. It's a little more involved than just simply calling a function, but if you 'know' it exists, and the parameter types passed to it, then it should be pretty straightforward (catching errors, of course).
You'll need to Import the System.Reflection namespace, to make things easier.
btsdev
yes, it's that
can you explain me how to do that
can you give some examples of code to how call the dll functions.
thanks
mickyoun
Hi,
If all you want is to elimintate the need to distribute a separate DLL beside your executable, then another solution would be using the ILMerge utility:
http://msdn.microsoft.com/netframework/downloads/tools/default.aspx
Ron Barrett
Hello!
I would recommend embedding the external dll into your assembly and then using reflection to locate and load it. That would allow you to compile it all as one file. There are some fancy linkers on the market that allow you to do this but your scenario is pretty straightforward.
I hope this points you in the right direction.
Christopher
Adner
Can someone give me an example in vb
I'm trying convert the code from http://objecthead.blogspot.com/ to VB but still not working.
Thanks
Garry W
1 question, everytime my program run need run the code that you indicated from http://objecthead.blogspot.com/
Another thing: can give me the example code in vb I'm trying pass to vb but it's not working.
Thanks very much
E Hauck
So, after embedded dll's in program, how I can make reference to they functions
(example: to use the SendArp command, I need make the command:
<DllImport("iphlpapi.dll", ExactSpelling:=
True)> _ Public Shared Function SendARP(ByVal DestIP As Integer, ByVal SrcIP As Integer, <Out()> ByVal pMacAddr() As Byte, ByRef PhyAddrLen As Integer) As Integer End FunctionIf I embeb the dll, how can call the SendArp function
NUMBSCULL
Well you see that's the cool part. His code basically works by pointing the AppDomain to the embedded assembly before it goes and looked locally by probing and in the GAC. It's really the same as if you had copied the assembly locally as you've done before. So really in addtion to adding it to your project as a file and marking it as embedded you also just go reference it in your project as you would normally. You can call the SendArp function by just creating an instance of the referenced assembly and calling SendArp as usual.
Does that make sense Read his article again and see if it clicks...if not let me know and I'll give it another shot...
Christopher