|
First of all let me apologize for posting this without searching about it first.
I'm doing this because I'm in a hurry and I need to leave my work right now, and I was in the middle of this problem.
Well I'm starting on p/invoke just now and I can't make it work.
I created a class with all methods I need to call from the dll and it looks something like this:
[DllImport(@"MitraLib.dll", EntryPoint = "MitraConectaBD", CallingConvention = CallingConvention.StdCall)]
public static extern int MitraConectaBD(IntPtr AsUsuario, IntPtr AsSenha, IntPtr AsBanco, bool AbLoginPrompt);
Well, with the class created I started to code what I wanted:
public Form1()
{
Thread.CurrentThread.Name = "MAIN";
InitializeComponent();
IntPtr ptrLogin = Marshal.StringToHGlobalAnsi("oscar");
IntPtr ptrSenha = Marshal.StringToHGlobalAnsi("1");
IntPtr ptrDataBase = Marshal.StringToHGlobalAnsi("Gerencial2000i");
int retCode = MitraLib.MitraConectaBD(ptrLogin, ptrSenha, ptrDataBase, false);
Marshal.FreeHGlobal(ptrLogin);
Marshal.FreeHGlobal(ptrSenha);
Marshal.FreeHGlobal(ptrDataBase);
}
Well, when I try to compile my project I get an exception saying
(translated to english by myself)
It wasn't possible to load the DLL 'MitraLib.dll': It wasn't possible to find the specific module(Exception HRESULT: 0x8007007E)
or something like that.
Does anyone have any clue?
I'm sorry again for posting this withou searching the forum (although I googled it but didn't find anything)
ps. MitraLib.dll is a Delphi code.
Thanks in advance
Oscar
|
|
|
|
|
Not sure, but try removing the namespace:
int retCode = MitraLib.MitraConectaBD
|
|
|
|
|
Hi there!
Thanks for the attention.
But no, that didn't work. When I remove MitraLib the method MitraConectaBD stops belonging to the current namespace!
I forgot to tell on my first post: My MitraLib.dll file is already in bin\Debug and in bin\Release folders.
Also, in the project properties, the output path in in Build tab is already set to bin\Debug
But still doesn't work...
Is there any extra configuration I should make to work?
Thanks again!
|
|
|
|
|
Another thing,
I've just copied MitraLib.dll to my system32 folder and now it works!
But how can I make it search in bin\Debug ?
Thanks again!
|
|
|
|
|
Make sure you have MitraLib.dll in a folder where the compiler can find it. I'd try to have it in the same folder as your source code or C:\Windows\System32. Be aware that you may need to put it in your <project folder="">/bin/Debug folder if you want to run and debug the project.
|
|
|
|
|
Hi Kythen, thanks for the answer!
I forgot to tell on my first post: My MitraLib.dll file is already in bin\Debug and in bin\Release folders.
Also, in the project properties, the output path in Build tab is already set to bin\Debug
But still doesn't work...
Is there any extra configuration I should make to work?
ps. Just copied MitraLib.dll to system32 folder and now it works!
How can I change the path of my project to search in bin\Debug??
Thanks again!
|
|
|
|
|
Hi,
this looks like a run-time error. Make sure your DLL is in a folder where Windows will look for it
(using PATH). Good candidates are: the folder holding your EXE (that would be a /bin/debug folder)
or C:\Windows\system32 (not recommended).
|
|
|
|
|
Hi Luc, thanks for the answer!
I forgot to tell on my first post: My MitraLib.dll file is already in bin\Debug and in bin\Release folders.
Also, in the project properties, the output path in Build tab is already set to bin\Debug
But still doesn't work...
Is there any extra configuration I should make to work?
ps. Just copied MitraLib.dll to system32 folder and now it works!
How can I change the path of my project to search in bin\Debug??
I can't let my application search in system32... it's not good for me...
Thanks again!
|
|
|
|
|
Hi,
AFAIK the EXE will look first in its own folder, only then use the Environment Variable "PATH" to
determine where to look next.
Be careful with outdated DLL copies.
I would suggest to remove all your DLL copies, and have just the one in the EXE folder itself.
Also make sure no older copies of your program are still running!
What is your OS?
|
|
|
|
|
Hi Luc,
I'm sorry but I don't know what 'AFAIK' is (I'm brazilian with a limited english knowledge)
Anyway, I assume that you meant that the default path search is exacly bin\Debug.
I've just removed my MitraLib.dll from system32 and have it only in bin\Debug and it is not outdated.
I find it funny that my project can't find it no mather what I do.
I'm googling since 9am and I can't find a way to force my project to look in bin\Debug...
I'm using windows XP
--------
LOL... I just got the brilliant idea to move every dll related with MitraLib.dll to the EXE folder and now it works fine... I though that the problem was not finding MitraLib... but it seems that the problem was that it couldn't find every dll related to it...
Anyway... I had to read alot about this... I think i'm a little better at p/invoke..
Now I can finally start developing.
Thanks for the help Luc!
|
|
|
|
|
As Far As I Know
you didn't mention multiple DLL files
once your EXE finds one somewhere, that DLL will look for whatever it needs
in its folder, not your EXE's folder.
yes the easiest approach is to have all your DLLs in your EXE folder.
you're welcome.
|
|
|
|
|
I have a list that holds many controls(e.g) Panels and a function that knows how to print a print form the list for a given index. I want to print 2 panels per page how can i build this algorithm.
|
|
|
|
|
I'd use the panels method that copies the control to a bitmap ( DrawToBitmap ? ), then write a print method that arranges those bitmaps as required.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Sweet Zombie Jesus is this a hard problem to solve.
I'm making an IDE for a scripting language I made up and I want to borrow some of Visual Studio's manuerisms when it come to editing the properties of an object in a propertygrid.
I have a type called ScriptEvent. I want to completely emulate the behavior you see when you try and edit an event in VS. (Opens a document, scrolls to position, etc...)
If there is already a decent way. Please point me in that direction.
If there isn't a clean way, then how do I make a property in a propertygrid talk to a non-modal dialog to get a value....
|
|
|
|
|
Not sure if this helps, but have you looked at using the Visual Studio Shell[^]?
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
I've made a few editors in the shell before, but this is going to be part of a larger unique editor.
|
|
|
|
|
Ok. Well, your question is a rather large one. Are you having trouble with a particular part? Or you don't know where to get started?
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
I'm not really sure were the best place to start is. I've gone down a few rabbit holes so far...
|
|
|
|
|
Have your ScriptEvent type keep a reference to where the event handler is: the document path and the line number. When the property is modified, open that document in your editor and scroll down to the line number.
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Ok I have found that this is not possible but I wanted to know if anyone knew a way around this problem.
I have an abstract item class called AbstractMyItem, from this class I implement several items, one for example is MyBox. So the code for the box is:
public abstract class AbstractMyItem{}
public class MyBox: AbstractMyItem{}
For each item I want there to be a provider that performs some basic functionality for example:
public interface IMyItemProvider{
public AbstractMyItem [] LoadItems();
}
So for each I create a provider from the interface:
public class MyBoxProvider : IMyItemProvider {
public AbstractMyItem [] LoadItems();
}
However this creates a lot of casting as I have to cast the AbstractMyItem class to the MyBox class. It makes more sense to use generics like this:
public interface IMyItemProvider<T> where T : AbstractMyItem{
public T[] LoadItems();
}
public class MyBoxProvider : IMyItemProvider<MyBox>{
public MyBox[] LoadItems();
}
However as I said before I need to create a list of these providers. So in theory the obvious solution is:
List<IMyItemProvider<AbstractMyItem>> providers = new List<IMyItemProvider<AbstractMyItem>>();
providers.Add((IMyItemProvider<AbstractMyItem> ) MyBoxProvider);
However this will not work. You can't cast the concrete class to a the interfaced generic type. This does not work:
IMyItemProvider<AbstractMyItem> instance = (IMyItemProvider<AbstractMyItem> ) MyBoxProvider;
So the question. Anyone know of a good way to get around this problem? To be able to use generics with a list and assign my concrete classes to it?
It would be nice to say (I know this not real code).
List<IMyItemProvider<inherits AbstractMyItem>> providers = new List<IMyItemProvider<inherits AbstractMyItem>>();
providers.Add((IMyItemProvider<AbstractMyItem> ) MyBoxProvider);
|
|
|
|
|
What you want to do is not possible as of C# 3. You may want to read Eric Lippert's series of articles on adding covariance and contravariance to a hypothetical version of C#[^].
In the meantime, here are some work arounds:
-Use a non-generic list.
-Make IMyItemProvider implement a non-generic interface, call it IProvidesItemsBase , then make your list be of type List<IProvidesItemsBase> . This will work, of course when you call LoadItems, you'd get back an array of AbstractMyItem s.
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Using C#, I need to deserialize an xml stream in input on a socket. The problem is that I don't know class type on which the stream xml is based. More specifically I have more than one class on which the xml stream could be based. How can I know the class type that I should use among those that I have available?
|
|
|
|
|
davegali wrote: The problem is that I don't know class type on which the stream xml is based.
Then you are screwed.
|
|
|
|
|
is there any way to run the dropped file to explorer ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
What dropped file? What explorer?! Oh my God where's my shoe!!
So, what are you trying to do?
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|