|
Comments and Discussions
|
 |
 |
How do I implement a DllMain method where I can initialize my dll?
The DllExport parser should detect "DllMain" method and add ".entrypoint" directive in ".il" file.
the ".entrypoint" is present but when the 3rd part exe (not .Net code) try to load dll it generate a loading dll error.
Profiling the exe with Dependency Walker it seem that call to DllMain return null.
What am I doing wrong?
this is my implementation:
[DllExport]
[return: MarshalAs(UnmanagedType.Bool)]
public static bool DllMain ([MarshalAs(UnmanagedType.I4)]int hInstace,
[MarshalAs(UnmanagedType.I4)]int Reason,
[MarshalAs(UnmanagedType.I4)]int Reserved)
{
dllInitialized = true;
return true;
}
|
|
|
|
 |
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
|
|
|
|
 |
OK, so this works. Can anyone tell me why?
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,
ref Test2Struct t1)
{
t1.i1 = 20;
return 5;
}
Regards,
Mike
|
|
|
|
|
 |
check this[^] not mine solution but could be even better ...
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
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?
|
|
|
|
 |
do you have C/C++ header files for this API calls ... coz i don't get it ...
REMEBER about: calling conventions[^] if you are using bad it will crash your app
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
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?
|
|
|
|
 |
with this hack you can only build for x86 or x64. Windows CE it's not supported.
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
Thank you for your quick reply.
Now I'm working on a project which need to load VB.NET by c++ program on Windows CE, do you have any idea of that?
Thank you.
|
|
|
|
 |
i'll go for COM Interop[^]
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
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
|
|
|
|
 |
Ok I got it.It should be used like this
[ExportDllAttribute("DotNetMethod",System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
|
|
|
 |
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.
|
|
|
|
|
 |
Thanks Selvin,
My problem is simpel, i have a .Net made dll file and i want export some functions from that dll file. Can u help me to use ure code? Thanks
|
|
|
|
 |
My program cant't change already existing dll
You need compile this dll and add ExportDll atribute to the exported function
Look at wcf sample from post above.
It contains C# and c++ project
In C# project we export some function and in C++ project we call it.
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
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?
|
|
|
|
 |
try to run dialog in other thread
void exportfunction()
{
ManualResetEvent wait = new ManualResetEvent(false);
var thread = new Thread(() =>
{
Application.Run(new Form1(wait));
//in OnClosed add "wait.Set();"
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
wait.WaitOne();
}
or even in new AppDomain
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
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?
|
|
|
|
 |
1) this is not a solution ... you can easily find "SQLAuthentification" using .net reflector
2) System.Data.SqlClient.SqlConnection != ADODB.Connection that's why excel crashes ... if u really want to do it this way u need to add references to ADODB in .NET project and use ADODB.Connection it instead of SqlConnection
3) u can also build ".NET addin to excel" or "Excel automation in .NET" without any VBA code ...
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
Tanks a lot for your immediate reply!
Excel still crashes! My new code:
---------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Data;
using System.Data.OleDb;
using ADODB;
namespace ConnectionDLL
{
public class ConnectionSQLServer
{
[ExportDllAttribute.ExportDll("Connect",
System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.AsAny)]
public static ADODB.Connection Connect(String Datenbank)
{
ADODB.Connection cnn = new ADODB.Connection();
int intConnectionMode = (int)ConnectModeEnum.adModeUnknown;
String Username = "Test";
String Password = "testtest";
cnn.Open("Provider='SQLOLEDB';Data Source='PETER-PC\\PETER'; Initial Catalog='"+ Datenbank + "';",Username , Password, intConnectionMode);
return cnn;
}
}
}
---------------------------------
Private Declare Function Connect Lib "C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\ConnectionDLL\ConnectionDLL\bin\Debug\connectiondll.dll" _
(ByVal stDB As String) As ADODB.Connection
Sub SQL()
Dim conn1 As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim comm As New ADODB.Command
conn1 = Connect("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
|
|
|
|
 |
1. wrong string marshaling
2. do it by ref
3. i'm still thinking that is bad idea - u can debug the code and show connection string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Data;
using System.Data.OleDb;
using ADODB;
namespace ConnectionDLL
{
public class ConnectionSQLServer
{
[ExportDll("Connect", System.Runtime.InteropServices.CallingConvention.StdCall)]
public static void Connect([MarshalAs(UnmanagedType.BStr)]string Datenbank, ref object Connection)
{
Connection = new ADODB.Connection();
int intConnectionMode = (int)ConnectModeEnum.adModeUnknown;
string Username = "Test";
string Password = "testtest";
((ADODB.Connection)Connection).Open("Provider='SQLOLEDB';Data Source='PETER-PC\\PETER'; Initial Catalog='" + Datenbank + "';", Username, Password, intConnectionMode);
}
}
}
Private Declare Sub Connect Lib "ConnectionDLL.dll" (ByVal Datenbank As String, ByRef ret As Connection)
Sub SQL()
Dim conn1 As Variant
Dim rec As New ADODB.Recordset
Dim comm As New ADODB.Command
Call Connect("AdoDB", conn1)
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
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
Thanks a lot for your advice. Of course you are right! Visual Studio Tools for Office are not availabe in den Express Edition! The way I want to do it is better than the situation we have now.
When I start the Excel Code, the variant type of conn1 is different to the connection type of ret, Excel gives an error. Changing the Variant to ADODB.Connection is no solution. Excel still crashes.
|
|
|
|
 |
do you have same version MDAC(fx. 2.8) references in both solutions (C#, VBA)
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
[ExportDll("Connect", System.Runtime.InteropServices.CallingConvention.StdCall)]
public static void Connect([MarshalAs(UnmanagedType.AnsiBStr)]string Datenbank, ref object Connection)
{
Connection = new ADODB.Connection();
int intConnectionMode = (int)ConnectModeEnum.adModeUnknown;
string Username = "użytkownik";
string Password = "hasło";
((ADODB.Connection)Connection).Open("Provider='SQLNCLI10';Data Source='SERWER'; Initial Catalog='" + Datenbank + "';", Username, Password, intConnectionMode);
}
Private Declare Sub Connect Lib "C:\Users\Selvin\Documents\Visual Studio 2010\Projects\ConnectionDLL\ConnectionDLL\bin\Debug\ConnectionDLL.dll" _
(ByVal aa As String, ByRef ret As Variant)
Sub SQL()
Dim conn1 As Variant
Dim comm As New ADODB.Command
Dim rec As New ADODB.Recordset
Call Connect("CDNXL_BAZA", conn1)
comm.ActiveConnection = conn1
SQLcmd = "SELECT * FROM CDN.Nazwy"
comm.CommandText = SQLcmd
rec.Open comm
ActiveCell.Value = 0
ActiveCell.CopyFromRecordset rec
End Sub
it's working for me ...
i got MDAC 2.8 references added to both solutions
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
Thank you for your prompt answer!
On my machine I only have "Microsoft Data Access Components Installed Version 2.5" which I added to both (C#,VBA). Excel crashes. I tried to download MDAC 2.81 SP 1, installation is not accepted. I read that MDAC 2.8 should be installed with Windows XP SP2, I use of course SP3. Why can't I choose MDAC 2.8?
I use Visual Studio Express 2008 and Office 2010.
It's so annoying!
modified on Sunday, February 13, 2011 10:55 AM
|
|
|
|
 |
my mistake - a typing error and of course I have to use "Microsoft ActiveX Data Objects 2.8 Library"!
Now I changed my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Data;
using ADODB;
using System.Xml;
using System.IO;
using System.Security.Cryptography;
namespace ConnectionDLL
{
public class ConnectionSQLServer
{
[ExportDllAttribute.ExportDll("Connect",
System.Runtime.InteropServices.CallingConvention.StdCall)]
public static void Connect([MarshalAs(UnmanagedType.AnsiBStr)]string Datenbank, ref Object Connection)
{
Connection = new ADODB.Connection();
int intConnectionMode = (int)ConnectModeEnum.adModeUnknown;
String Username = Crypto.DecryptMessage("eJvw+LEDxnI=","FinON");
String Password = Crypto.DecryptMessage("+RQ06KwJSrRQmHYwoInNmw==", "FinON");
((ADODB.Connection)Connection).Open("Provider='SQLOLEDB';Data Source='PETER-PC\\PETER'; Initial Catalog='" + Datenbank + "';", Username, Password, intConnectionMode);
}
}
public partial class Crypto
{
public static string EncryptMessage(string plainMessage, string password)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.IV = new byte[8];
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[0]);
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
MemoryStream ms = new MemoryStream(plainMessage.Length * 2);
CryptoStream encStream = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
byte[] plainBytes = Encoding.UTF8.GetBytes(plainMessage);
encStream.Write(plainBytes, 0, plainBytes.Length);
encStream.FlushFinalBlock();
byte[] encryptedBytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(encryptedBytes, 0, (int)ms.Length);
encStream.Close();
return Convert.ToBase64String(encryptedBytes);
}
public static string DecryptMessage(string encryptedBase64, string password)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.IV = new byte[8];
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[0]);
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
byte[] encryptedBytes = Convert.FromBase64String(encryptedBase64);
MemoryStream ms = new MemoryStream(encryptedBase64.Length);
CryptoStream decStream = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
decStream.Write(encryptedBytes, 0, encryptedBytes.Length);
decStream.FlushFinalBlock();
byte[] plainBytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(plainBytes, 0, (int)ms.Length);
decStream.Close();
return Encoding.UTF8.GetString(plainBytes);
}
}
}
It works! But if I debug my Excel-VBA-Code I can see the ConnectionString. After opening the Connection in the DLL I tried to change the information in the ConnectionString inside the DLL - this does'nt work.
I think debugging the DLL doesn't show the SQLAuthentication - isn't it?
How can I hide the ConnectionString in EXCEL? I should do something in den DLL -
|
|
|
|
 |
New Idea!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADODB;
using System.Xml;
using System.IO;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace PeterConDLL
{
public class PeterConDLL
{
[ExportDllAttribute.ExportDll("ConnectRVT",
System.Runtime.InteropServices.CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)]
public static String[,] ConnectRVT([MarshalAs(UnmanagedType.AnsiBStr)]string Datenbank, [MarshalAs(UnmanagedType.AnsiBStr)]string SQLCmd)
{
ADODB.Connection Connection = new ADODB.Connection();
int intConnectionMode = (int)ConnectModeEnum.adModeUnknown;
String Username = Crypto.DecryptMessage("eJvw+LEDxnI=","FinON");
String Password = Crypto.DecryptMessage("+RQ06KwJSrRQmHYwoInNmw==", "FinON");
((ADODB.Connection)Connection).Open("Provider='SQLOLEDB';Data Source='PETER-PC\\PETER'; Initial Catalog='" + Datenbank + "';", Username, Password, intConnectionMode);
ADODB.Recordset rs = new ADODB.Recordset();
rs.Open(SQLCmd, Connection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, -1);
int fieldcount = rs.Fields.Count;
int reccount = 0;
while (rs.EOF == false)
{
reccount = reccount + 1;
rs.MoveNext();
}
rs.MoveFirst();
String[,] SQLErgebnis = new String[reccount, fieldcount];
for (int n = 0; n < reccount; n++)
{
for (int m = 0; m < fieldcount; m++)
{
SQLErgebnis[n, m] = rs.Fields[m].Value.ToString();
}
rs.MoveNext();
}
return SQLErgebnis;
}
}
public partial class Crypto
{
public static string DecryptMessage(string encryptedBase64, string password)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.IV = new byte[8];
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[0]);
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
byte[] encryptedBytes = Convert.FromBase64String(encryptedBase64);
MemoryStream ms = new MemoryStream(encryptedBase64.Length);
CryptoStream decStream = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
decStream.Write(encryptedBytes, 0, encryptedBytes.Length);
decStream.FlushFinalBlock();
byte[] plainBytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(plainBytes, 0, (int)ms.Length);
decStream.Close();
return Encoding.UTF8.GetString(plainBytes);
}
}
}
Private Declare Function ConnectRVT Lib _
"C:\Dokumente und Einstellungen\Peter\Eigene Dateien\Visual Studio 2008\Projects\PeterConDLL\PeterConDLL\bin\release\PeterConDLL.dll" _
(ByVal Datenbank As String, ByVal SQL As String) As Variant
Sub PeterSQL()
Datenbank = "AdoDB"
SQLCommand = "Select * from Adressen"
Dim Ergebnis As Variant
Ergebnis = ConnectRVT(Datenbank, SQLCommand)
End Sub
Excel crashes - marshalling problem??
|
|
|
|
 |
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
|
|
|
|
 |
http://esilo.pl/LibraryX.zip
it works from me
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
Thank you for your example.
My problem was in configuration.
My bad configuration:
ilasmpath = C:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe
RegAsm was calling from C:\Windows\Microsoft.NET\Framework\v2.0.50727
When I setting for .NET v2..... build is successed but program communicating through this library has a problem. The unmanaged program calling my library cannot create instance of StringBuilder.
When I Setting For .NET v4.0 everything is ok.
I would like running on .NET v2.0
Could you help me ?
|
|
|
|
 |
>Could you help me ?
i may help you ... but i need more information ...
minimal code of exported function and callin' function
like this (i dont know if this code actually working)
C#
void Blabla(out StringBuilder builder)
{
builder = new StringBuilder();
}
native
void CallDoNet()
{
LPSTR* somePointer;
Blabla(somePointer);
MessageBox(0, *somePointer, 0, 0);
}
why i need this ... i'm sure that you made a mistake in marshalling
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
function PluginGetSysAndClassName(Vysl: PAnsiChar{*}): DWORD; stdcall;
[ExportDll("PluginGetSysAndClassName", CallingConvention.StdCall)]
public static UInt32 PluginGetSysAndClassName([MarshalAs(UnmanagedType.LPStr)] StringBuilder progIdCom)
|
|
|
|
 |
I resolved it. Replace StringBuilder by pointer of byte
[ExportDll("PluginGetSysAndClassName", CallingConvention.StdCall)]
public unsafe static UInt32 PluginGetSysAndClassName(byte* progIdCom)
{
byte[] ansiName = Encoding.ASCII.GetBytes("RedengeKit.Plugin");
if (progIdCom != null || ((byte*)IntPtr.Zero) != progIdCom)
{
Marshal.Copy(ansiName, 0, (IntPtr) progIdCom, ansiName.Length);
}
return Convert.ToUInt32(ansiName.Length);
}
|
|
|
|
 |
what about:
[ExportDll("PluginGetSysAndClassName", CallingConvention.StdCall)]
public static uint PluginGetSysAndClassName([MarshalAs(UnmanagedType.LPStr)] ref string progIdCom)
{
progIdCom = "Something.Else"
return (uint)progIdCom.Length;
}
do you know how if "Vysl" pointer is just pointer or it pointing to allocated space?
second option is as you wrote a pointer
but you dont need to using unsafe use IntPtr instead byte*
...works fascinates me...i can stare it for hours...
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
First Posted | 9 Nov 2006 |
Views | 218,828 |
Downloads | 2,666 |
Bookmarked | 81 times |
|
|