 |

|
i already try the tutorial but when i try to exportdll.exe i got this message could not load file or assembly 'ExportDllAttribute version 1.0.0.0 ...' or one of its depedencies. the system cannot find the file specified
anyone could help me ?
|
|
|
|

|
Hi Selvin,
Thanks for the effort you put into this project.
Just to let others learning through the linked WCF example, I get a VS 2010 Build Error of
"Error 1 The command ""C:\Users\chais140\Documents\Visual Studio 2010\Projects\ExportDLL_WCF_Example\WCF\ExportDll.exe" "C:\Users\chais140\Documents\Visual Studio 2010\Projects\ExportDLL_WCF_Example\Debug\WCF.dll" /Debug" exited with code -1."
I installed the example(s) without any modification. The other example (LibraryX) built without any errors.
By the way, am trying to build a .NET assembly that will be called from VB6.
Chuck
|
|
|
|

|
How do I export a function using a struct as a parameter? I tried this, but my C++ client failed.
public struct Test2Struct
{
[MarshalAs(UnmanagedType.I4)]
public int i1;
}
[ExportDll("Test1", CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I4)]
public static int Test1([MarshalAs(UnmanagedType.BStr)]string s1,
[MarshalAs(UnmanagedType.BStr)]ref string s2,
[MarshalAs(UnmanagedType.Struct)]ref Test2Struct t1) { return 5; }
Regards,
Mike
|
|
|
|
|

|
This help solve a major headache by eliminating the need to wrap the managed methods in COM.
|
|
|
|

|
I´m using ExportDll to access some Aplcation API on .NET DLL's.
The first problem I encountered is usum static object to mantain state. Using the Dll en a c# program It works as expected. Using it oc C++ it assert on caling the exported function.
Also if in the exported funcion I call a second function (not exported) that uses .Net imported classes as parameter, the function assert oc calling. If i put the code on the body of the functio It works correcly.
Last on function assert it is very hard to understand the motive, because it not catch by try catch.
Can i with this method export a class and mantain state?
|
|
|
|

|
Hi I am getting this error:
Kinect Dll Plugin -> C:\Users\HMS\Documents\Kinect(David)\Kinect Working Code\Kinect Dll Plugin\Kinect Dll Plugin\bin\Release\KinectFramework.dll
KinectFramework.il(497) : warning -- Reference to undeclared extern assembly 'ExportDllAttribute'. Attempting autodetect
KinectFramework.il(497) : warning -- Failed to autodetect assembly 'ExportDllAttribute'
Could not open Release.il
When I run the tool. Any ideas?
Thanks!
|
|
|
|

|
Hi When I run the command
ExportDll.exe dllPath\myfile.dll
I get the error
Target Should be Dll!
Note: dllPath and myfile.dll are real files/paths, just used placeholders for simplicity.
|
|
|
|

|
Hi Selvin, first of all: Thanks for your great work!
There seems to be an issue with changing the calling convention. It does not (always) seem to work, at least not in my case.
Whatever I put as parameter 2 of ExportDllAttribute, it always generates StdCall.
I took a look at your code and had to add one statement to make it work:
In ExportDll, line 315 of file Program.cs contained
else
Log("\tChanging calling convention: " + attr.Value);
I changed it to
else {
Log("\tChanging calling convention: " + attr.Value);
methoddeclaration = methodbefore + "modopt([mscorlib]" + attr.Value + ") " + methodname + methodafter;
}
Now it's working for me
modified on Friday, September 16, 2011 12:12 AM
|
|
|
|

|
In Visual Studio 10 I set up DLLExport as an External Tool and put the following in the Arguments field:
"$(TargetPath)" \$(ConfigurationName) // DOESN'T WORK
The above gives an error during IL recompilation.
Through experiment I found the following works instead:
$(TargetPath) $(ConfigurationName) // WORKS
The above works, compiling an unmanaged DLL to the obj directory.
|
|
|
|

|
I made a dll by c# for Pocket PC and exported functions.
But when I calling exported functions in client program, it crashed.
Could you give some informations?
|
|
|
|

|
I spent a full day searching the internet for answer to this question. There were so many dead ends, but this was EXACTLY what I was looking for. Your solution works flawlessly. Thank you so very much.
|
|
|
|

|
in C# dll I got:
[ExportDll("Test",
System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int Test ( ref string a ) { a = "TEST"; }
in c++ I use dynamic linking to the dll, successfully got handle from GetProcAddress, but I get error in runtime when calling a method:
typedef int (__stdcall *MYPROC)(char **);
int main () {
HINSTANCE hinstLib;
MYPROC MyPoc;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary(TEXT("mydll.dll"));
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "Test");
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
char *s1 = "test";
(MyProc) (&s1);
cout << s1;
}
fFreeResult = FreeLibrary(hinstLib);
}
}
I got runtime error on line where I call method. If I use char * (and ref char in c#) everything is ok. What I'am doing wrong?
|
|
|
|

|
I am getting problem with the solution you mentioned.What i did is downloaded your project and converted it into VS2010 ,successfully build it and Add the exportDllAttribute reference in my C# dll project.But when i compile the solution it gave me the following errors
error CS0426: The type name 'ExportDll' does not exist in the type 'ExportDllAttribute'
error CS0426: The type name 'ExportDllAttribute' does not exist in the type 'ExportDllAttribute'
Below is the code i used
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Runtime.CompilerServices;
namespace DotNetLibrary
{
public class DotNetClass
{
[ExportDllAttribute.ExportDll("DotNetMethod",System.Runtime.InteropServices.CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.AsAny)]
public static string DotNetMethod(string input)
{
return "Hello " + input;
}
}
}
Kindly let me know if i am doing something wrong.
Regards,
Hassan Tariq
|
|
|
|

|
Hi Selvin,
where must i write this:
public class SomeClassName
{
[ExportDllAttribute.ExportDll("ExportNameOfFunction",
System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static void SomeFunctionName()
{
System.Console.WriteLine("I really do nothing");
}
}
Thanks.
|
|
|
|

|
Worked great! You saved my day
|
|
|
|

|
I ran this process and ran dllviewer and it shows no exported functions. I tried this in C# and vb.net and could not get either to work. Any assistance would be great.
|
|
|
|

|
Hi.
I have created a C# DLL with form and create a function to start the dialog.
I have user DLLExport project to create an unmanaged interface to VC 6.0.
When i use the dll in a VC 6.0 project the TAB keys don't work.
Any ideas?
|
|
|
|

|
I use our solution with great success!
Now I tried the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
namespace ConnectionDLL
{
public class ConnectionSQLServer
{
[ExportDllAttribute.ExportDll("Connection",
System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.AsAny)]
public static SqlConnection Connect(String Datenbank)
{
string connectionString = null;
SqlConnection cnn ;
connectionString = "Data Source=PETER-PC\\PETER;database=AdoDB;User ID=Test;Password=testtest";
cnn = new SqlConnection(connectionString);
try
{
//cnn.Open();
}
catch (Exception ex)
{
//
}
return cnn;
}
}
}
I want to use the exported DLL like this in EXCEL:
Private Declare Function Connection Lib "C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\ConnectionDLL\ConnectionDLL\bin\Debug\connectiondll.dll" _
(ByVal stDB As String) As Object
Sub SQL()
Dim conn1 As New Connection
Dim rec As New Recordset
Dim comm As New Command
conn1 = Connection("AdoDB")
conn1.Open
comm.ActiveConnection = conn1
SQLcmd = "SELECT Zuname FROM adressen where Vorname ='Markus'"
comm.CommandText = SQLcmd
rec.Open comm
ActiveCell.Value = 0
ActiveCell.CopyFromRecordset rec
End Sub
By the way - I didn't already use the parameter in den function "connection"! The objective of the DLL is to hide the SQLAuthentification, because if you hide the SQLAuthentification in the EXCEL module you are not safe, you can read the module which is secured with a password very easy with open office.
Excel crashes .... what's wrong?
|
|
|
|

|
I've validated your technique soon I after you published it -- it is uniquely great!
Also, I recently explained your technique and credited your work in my CodeProject Answer.
Thank you very much.
|
|
|
|

|
Thank you for this nice library. But I have a problem.
I want combination of COM and Export Functions in one library. But I run RegAsm I obtainthis message:
".... This is not a valid .NET assembly"
Please help me
|
|
|
|

|
I'm trying to make a drop-in-replacement for an existing unmanaged DLL using the scheme provided here. I don't have access to the code actually using the DLL so I can't change the interface. The original DLL exports its functions with stdcall decoration (that is, adding an underscore in front of the name and adding @+numparambytes at the end). Is there a way to produce these names automatically by the procedure described here? If not, would it be an (ugly) option to 'hard-code' the names of the exported functions identical to the ones in the existing DLL?
Also, why don't programs like http://www.nirsoft.net/utils/dll_export_viewer.html show any exported functions in the DLL generated by the method described here? MS dumpbin does show the names.
|
|
|
|

|
http://sites.google.com/site/robertgiesecke/
|
|
|
|

|
Your code is very great.
One of my colleagues used it but I am not getting the result as expected I followed your instructions but got the error:
Error 1 The type name 'ExportDllAttribute' does not exist in the type 'ExportDllAttribute' C:\Test Exercise\DemoExport\DemoExport\DemoExport\DBSqlHelper.cs 11 29 DemoExport
Is something I missed?
|
|
|
|

|
Hi,
First of all, love your library. However, when I export a previously-valid, signed COM-visible assembly, I can no longer register the assembly properly. I assume that one would have to "re-sign" upon the call to ilasm. How could this be done with your tool?
Thanks!
David
|
|
|
|

|
Functions without arguments good works.
But this:
C# code
using System.Runtime.InteropServices;
namespace TestDll
{
public class Class1
{
[ExportDllAttribute.ExportDll("Sum", System.Runtime.InteropServices.CallingConvention.StdCall)]
public static int Sum(int n1,int n2)
{
return n1+n2;
}
}
}
and C++ code
#include "stdafx.h"
#include<windows.h>
typedef int (* WCF2)(int n1,int n2);
int _tmain(int argc, _TCHAR* argv[])
{
HMODULE module=LoadLibrary(L"C:\\SRC\\ExportDll\\TestDll\\bin\\Release\\TestDll.dll");
WCF2 f = (WCF2)GetProcAddress(module,"Sum");
int res=f(2,3);
return 0;
}
don't works with all selected CallingConvention type. Error message:
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
|
|
|
|

|
I did everything exactly as the article says. When I run the ExportDLL.exe against my DLL it appears not to touch my DLL - well, at least the date time stamp and the size remain unchanged. What's going on?
Thanks - Tim
|
|
|
|

|
Unbelievably handy little app you have here.
Why the heck MS doesn't make this kind of thing available directly from the VS ide is beyond me.
Works perfectly!
5 stars!
vbfengshui
|
|
|
|

|
This all works but I cannot debug my C# DLL. I think the problem is that since the DLL was modified after it was compiled, the debugger sees it as no longer being in sync, and breakpoints are disabled and doesn't get hit.
Am I doing something wrong or is this a flaw in this concept (as far as debugging goes)?
|
|
|
|

|
Hi. There are some changes maded by me:
* added usage information
* added verbose option (tool is quiet by default now)
* added option to set out file name
* added relative paths support (rough)
* added wow64 path support (if ildasm path contains "program files", this tool looks at "program files (x86)" also). just for convenience
* added custom attributes support (previous version have an incorrect method parser; now tool shows warning in such cases)
* made some mistake corrections (e.g. ".custum" => ".custom")
Modified sources here: exportdll.zip
|
|
|
|

|
Hi Guys,
just want to ask if events(like ONCHANGE ...) are working within converted dll's as well?
|
|
|
|

|
hey, im trying to implement this in my projects in VB.NET and evey time i try to export my functions i get this
it find all my classes and functions and then it says its compiling them and thn this
test.il(385) : warning -- Reference to undeclared extern assembly 'ExportDllAttribute'. Attempting Autodetect
test.il(385) : warning -- Failed to autodetect assembly 'ExportDllAttribute'
then the command prompt comes back to me and my function isn't exported.
heres the code, this is just a test project though...
Imports System.Runtime
Imports ExportDllAttribute.ExportDllAttribute
Public Class Main
<exportdllattribute.exportdll("box",> _
Public Shared Sub box()
MsgBox("Hello")
End Sub
End Class
i have tried it with and without the 'Imports ExportDllAttribute.ExportDllAttribute' line and it is the same either way
please help!
|
|
|
|

|
This happens if my dll references another dll in the same folder (for interfaces). The happens because the assembly loader can't find the second dll (because it's looking in the folder with the DllExport exe, not the folder with the dll for processing).
Is there a reason you're using Assembly.Load(byte[]) instead of Assembly.LoadFrom(string filepath)?
In my project I'm using CurrentDomain.AssemblyResolve to help the loader find the extra files, eg:
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
return Assembly.LoadFrom(Path.Combine(Path.GetDirectoryName(filepath), args.Name.Split(',')[0] + ".dll"));
}
catch (Exception)
{
return null;
}
}
|
|
|
|
|

|
Hi
When I run dependency walker over a dll that has been created using ExportDll I get the following dlls that could not be found:
c:\windows\system32\ADVAPI32.DLL
c:\windows\system32\MPR.DLL
c:\windows\system32\SHLWAPI.DLL
c:\windows\system32\USER32.DLL
Do you know how or why this is happening?
|
|
|
|

|
hi I am working with vc6++ only.
how can I use MSTSC.MSRDPClient in c++ vc6++
only? (aspecially I am searching how to
sink the MSRdpClient_OnDisconnect Event
to a c++ win32 static linked lib. )
only simple code
|
|
|
|

|
Hi Selvin,
Could you explain to me step by step how to export a function in a visual basic dll created in Visual Studio 2008?
Thanks a lot
|
|
|
|

|
Hi all,
I created a dll in Visual Basic using Visual Studio 2008 and I need to export the only function (Ocr) in the dll. I tried what you wrote at "http://www.codeproject.com/KB/dotnet/DllExport.aspx" to export my dll but it doesn't change when I compile it since when I use Dependecy Walker I don't see any exported method in my dll. I summarize what I did following your instructions:
1)I created my dll in Visual Studio 2008 as a project Class Library in Visual Basic.My dll is called Bollettino.dll. It contains only a Sub called Ocr.
2) I downloaded the ExportDll code and I added ExportAttribute.dll as an address in my project .
3) Before the Sub Ocr I added in my code the statement
ExportDllAttribute.ExportDll("Ocr()", System.Runtime.InteropServices.CallingConvention.Cdecl); _
ecause ExportDll.exe needs to know which functions need to be exported.
4) I add in Project property named "Post-build event command" the following statement
C:\Release\ExportDll.exe C:\Projects_VS_2008\Bollettino\Bollettino\bin\Release\Bollettino.dll /$(ConfigurationName)
thata represents the paths of ExportDll and of my dll
5) I compile my dll but it doesn't happen...Because I don't see any exported method in my dll if I use Dependency Walker.
I don't receive any error messages and I don't understand why it doesn't work.
What is wrong in my procedure???
Can you help me??
I hope that this message could be read by Slevin who is the author of the article I refers to.
Thanks in advance.
Bye
P.S Here is the code:
Public Class Class1
'[ExportDll("Ocr",System.Runtime.InteropServices.CallingConvention.Cdecl)]
<ExportDllAttribute.ExportDll("Ocr()", System.Runtime.InteropServices.CallingConvention.Cdecl)> _
Public Sub Ocr()
Dim inputFile As String = "C:\\Boll.tif"
Dim strRecText As String = ""
Dim Doc1 As MODI.Document
Doc1 = New MODI.Document
Doc1.Create(inputFile)
Doc1.OCR() ' this will ocr all pages of a multi-page tiff file
Doc1.Save() ' this will save the deskewed reoriented images, and the OCR text, back to the inputFile
For imageCounter As Integer = 0 To (Doc1.Images.Count - 1) ' work your way through each page of results
strRecText &= Doc1.Images(imageCounter).Layout.Text ' this puts the ocr results into a string
Next
System.IO.File.Delete("C:\\test5.txt")
System.IO.File.AppendAllText("C:\\test5.txt", strRecText) ' write the OCR file out to disk
'System.IO.File.Create("C:\\test2.txt", strRecText)
Doc1.Close() ' clean up
Doc1 = Nothing
End Sub
End Class
|
|
|
|

|
Hello I have a question, this exe can compile a dll for 64 bits operating system or is necesary to change something?
thanks and regards
|
|
|
|

|
new source
few bugs fixed
-CallConvStdcall bug(thnx. Lesha M.)
-marshal( xxxxx) if you are using [return : MarshalAs( xxxx)] attribute
sample project both managed and unamanaged added
you can download it here
...works fascinates me...i can stare it for hours...
|
|
|
|

|
Hello,
I dont know how to integrate my .net class library project with your Exportdll and Exportdll attribute.
Could you please provide step by step guide to convert my dll in to unmanaged dll, as I am new to .net
Please advise.
Thanks in Advance.
Regards,
Kesavan
|
|
|
|

|
First of all, solution is excellent. Thank's a lot.
A little error occured in line 21 at the file ExportDllAttribute.cs, that disables export in Cdecl format.
There are:
dic[System.Runtime.InteropServices.CallingConvention.Cdecl] = typeof(CallConvStdcall).FullName;
Seem's to be:
dic[System.Runtime.InteropServices.CallingConvention.Cdecl] = typeof(CallConvCdecl).FullName;
|
|
|
|

|
When i add the exporting to post build action, it works without any problem. But when I try to do it manually like ExportDLL.exe path\dll_name, then i am getting following messages and it doesn't work.
Debug: False
Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402
Could anyone help, thanks.
|
|
|
|

|
Have you tried this with a strong named DLL?
It seems not to work...
Debug: True
Could not load file or assembly '32768 bytes loaded from ExportDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e90ce7b9c6c47c11' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(3089,13): error MSB3073: The command ""C:\TerminalServicesRISPACS\Code\RISiExtend\TangoCentricity\src\Bridge\VirtualChannel\ExportDll\ExportDll\bin\Debug\ExportDll.exe" "C:\TerminalServicesRISPACS\Code\RISiExtend\TangoCentricity\src\Bridge\VirtualChannel\RisVirtualChannelClient\bin\Debug\RisVirtualChannelClient.dll" /Debug
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(3089,13): error MSB3073: " exited with code -1.
Done building project "RisVirtualChannelClient.csproj" -- FAILED.
|
|
|
|

|
I was wondering if anyone could help me with this. I had a hunch that this would be useable in-conjunction with DllMain which is exported by regular Win32 DLL's. I tried the following code and loaded it using LoadLibrary in unmanaged code:
using System;
using System.Collections.Generic;
using System.Text;
namespace InjectTest1
{
public class EntryPoint
{
[ExportDllAttribute.ExportDll("DllMain",
System.Runtime.InteropServices.CallingConvention.StdCall)]
int DllMain(IntPtr Module, int Reason, IntPtr Reserved)
{
System.Windows.Forms.MessageBox.Show("This is a test.");
return 1;
}
}
}
However it is not automatically called. I know you can call DllMain with GetProcAddress, but I was hoping you could do this with legacy applications of which you do not possess the source-code.
Thanks to anyone that has any information!
|
|
|
|

|
First of all, great work. I have been looking for a while now for something that will be anywhere closer to allowing me to export a function from a .NET assembly. I hope your work will get me there.
I am trying to use your code to export a method in an assembly for use by RunDll32.exe. The prototype that RunDll32.exe expects is:
void CALLBACK RunDll_FunctionName(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
I created a class where I have a method defined as follows:
public static void MyMethod_RunDLL(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow)
I use the ExportDllAttribute with "MyMethod_RunDLL" as the export name. I have tried all different calling conventions.
Any idea why RunDll32.exe may not find the exported method? Perhaps I am not using the code as intended?
|
|
|
|

|
Everything works great with C#, but I can't seem to get this working with VB.NET code.
In the command prompt when I try to execute it with a VB.NET dll, all i get is Debug: False.
When I do it with a C# dll, it returns a lot more data.
Is there something that I must do special to make it work with VB?
-- modified at 5:29 Friday 9th March, 2007
Well I fixed my issue, which was completely my mistake. You have to make sure the function static/shared. I forgot to make it shared in vb.
Thanks for this great tool!
-- modified at 10:58 Sunday 11th March, 2007
|
|
|
|

|
There is an error in source code, making impossible to export more than one method.
Line 85 in Program.cs of ExportDLL project should be changed from:
dic[type.FullName] = new Dictionary(...);
to:
if (dic.ContainsKey(type.FullName)==false)
{
dic[type.FullName] = new Dictionary(...);
}
Thanks for nice article.
|
|
|
|

|
Hi ,
I'm quite new of c++ ,and I don't know how i can load the exported function with c++.
Would you be so kind to post an example ? Thanks ... Sorry for my english.
-- modified at 3:58 Friday 10th November, 2006
|
|
|
|

|
Hi there!
This seem interesting but i can't download the files.
Got following message:
File not Found
The file '/useritems/DllExport/DllExport_src.zip' doesn't exist.
Kind regards
|
|
|
|
 |