DLL Import

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a general DLL "genDLL.dll",this dll open other dlls by calling
generalDll.openDll("dll1.dll").
I mad a form with got dll name in new,and then this for open the new dll by calling the openDll function.
the problem is when I make more than one instance of this Form from MDI the All form work with same dll even if thay are deferent.

The following Is what I do in MDI form :
1- childForm childForm_1 = new childForm("Dll1.dll");
2- childForm childForm_2 = new childForm("Dll2.dll");
3- childForm childForm_3 = new childForm("Dll3.dll");
************
in childForm
***********
private string dllFileName;
public childForm(string FileName)
{
this.dllFileName = FileName;
}

[DllImport("generalDll.dll")]
extern static int OpenDll(string DllName);

private void MemoryShow_Load(object sender, System.EventArgs e)
{
OpenDll(dllFileName);
}

How to creat new DLL instance?
 
Yosi,

From what I can tell, you want to call the same function that is defined
in different DLLs. You can't do this at runtime through the P/Invoke layer,
it has to be known at compile time.

However, in the next version of .NET, you will be able to load a DLL
dynamically, get the address of a function in it, and then map it to a
delegate with the same signature. This should allow you to do what you
want. However, that is still a ways away.

If you need a solution now, you should write an unmanaged piece of code
which will take the dll name, and the function you want to execute, as well
as the parameters, and execute it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I have a general DLL "genDLL.dll",this dll open other dlls by calling
generalDll.openDll("dll1.dll").
I mad a form with got dll name in new,and then this for open the new dll
by calling the openDll function.
the problem is when I make more than one instance of this Form from MDI
the All form work with same dll even if thay are deferent.
The following Is what I do in MDI form :
1- childForm childForm_1 = new childForm("Dll1.dll");
2- childForm childForm_2 = new childForm("Dll2.dll");
3- childForm childForm_3 = new childForm("Dll3.dll");
************
in childForm
***********
private string dllFileName;
public childForm(string FileName)
{
this.dllFileName = FileName;
}

[DllImport("generalDll.dll")]
extern static int OpenDll(string DllName);

private void MemoryShow_Load(object sender, System.EventArgs e)
{
OpenDll(dllFileName);
}

How to creat new DLL instance?
 
I think you're getting confused between classes, DLLs, and ActiveX (COM) DLLs.
Classes are programmatic objects that you instantiate instances of.
DLLs are blocks of code that are loaded (normally automatically when needed) into the application's memory space, so that it can call the *FUNCTIONS* the DLL exports.
ActiveX (COM) DLLs are a special type of DLL that expose language-independent classes and conform to strict specifications and have things like interfaces etc, their complexity is huge but since they are very standard automating the creation and consumption of them is a relatively easy process.

I think you need to take a step back - you appear to not be able to see the wood for the trees.
 
No ,I want to call same function in same DLL, the Dll manage the Instance of DLL.
When I call Open the DLL creat new DLLInstance.
What I can't UnderStand is how all the variable in the ChildForm Instants is deferent but the dll instance is same?

What I know Is when I make new Class Instance all variables will reallocated, And Also the DLL variables (new Instance) !!!!! Is it True this work in MFC ? ????????????


Nicholas Paldino said:
Yosi,

From what I can tell, you want to call the same function that is defined
in different DLLs. You can't do this at runtime through the P/Invoke layer,
it has to be known at compile time.

However, in the next version of .NET, you will be able to load a DLL
dynamically, get the address of a function in it, and then map it to a
delegate with the same signature. This should allow you to do what you
want. However, that is still a ways away.

If you need a solution now, you should write an unmanaged piece of code
which will take the dll name, and the function you want to execute, as well
as the parameters, and execute it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,
I have a general DLL "genDLL.dll",this dll open other dlls by calling
generalDll.openDll("dll1.dll").
I mad a form with got dll name in new,and then this for open the new dll
by calling the openDll function.
the problem is when I make more than one instance of this Form from MDI
the All form work with same dll even if thay are deferent.
The following Is what I do in MDI form :
1- childForm childForm_1 = new childForm("Dll1.dll");
2- childForm childForm_2 = new childForm("Dll2.dll");
3- childForm childForm_3 = new childForm("Dll3.dll");
************
in childForm
***********
private string dllFileName;
public childForm(string FileName)
{
this.dllFileName = FileName;
}

[DllImport("generalDll.dll")]
extern static int OpenDll(string DllName);

private void MemoryShow_Load(object sender, System.EventArgs e)
{
OpenDll(dllFileName);
}

How to creat new DLL instance?
 
BTW the things that tell me you are incredibly confused about how to use DLLs are the fact that you say things like

"this dll open other dlls" (DLLs don't *open* other DLLs as such... they might reference them, and as such cause them to be loaded aswell, but something that is 'open' is more like a database connection or a file)

"got dll name in new" BAD, BAD idea. (presumably from your crap grammar you mean you are passing the dll name to the constructor of a form?) What a JOKE! DLLs are a compile time thing, not decided dynamically at runtime. They are (or should be) a part of the application's main code, just in a separate file and possibly shared. They are not a magic lamp with which you can just summon up whichever genie you please.


Maybe you should use VB6 - it allows a lot more daft kludges than C# such as those you appear to be accustomed to.

Oh, and by the way. Learn english.
 
The one how need to back working with VB6 is you, before starting with your Jok.
The application I'm trying to do is already done in MFC.
We have 4 DLLs each one have open/read/write/close but each one have it own protocol for example Read/Write from/to IO/Uart/SMBus,I2C,Memory.....
The C# application Import General DLL witch have get DLL name and creat new instance this new instance is saved in the general DLL variable.
Each Form is same GUI but deferent execution In each one for example have Address = offset = 0x20 for example,
But the display value is deferents because each form shod read the value from deferents places , from IO,MEM,I2C,UART.....

when I open the form several times from command line (.exe) this working will but when this is a child of MDI form this not work,.
Thanks for helpping me , and belive me you need along time to do 50% of what I have already done

Beeeeeeeeeeeeves said:
BTW the things that tell me you are incredibly confused about how to use DLLs are the fact that you say things like

"this dll open other dlls" (DLLs don't *open* other DLLs as such... they might reference them, and as such cause them to be loaded aswell, but something that is 'open' is more like a database connection or a file)

"got dll name in new" BAD, BAD idea. (presumably from your crap grammar you mean you are passing the dll name to the constructor of a form?) What a JOKE! DLLs are a compile time thing, not decided dynamically at runtime. They are (or should be) a part of the application's main code, just in a separate file and possibly shared. They are not a magic lamp with which you can just summon up whichever genie you please.


Maybe you should use VB6 - it allows a lot more daft kludges than C# such as those you appear to be accustomed to.

Oh, and by the way. Learn english.



Hi,
I have a general DLL "genDLL.dll",this dll open other dlls by calling
generalDll.openDll("dll1.dll").
I mad a form with got dll name in new,and then this for open the new dll by calling the openDll function.
the problem is when I make more than one instance of this Form from MDI the All form work with same dll even if thay are deferent.

The following Is what I do in MDI form :
1- childForm childForm_1 = new childForm("Dll1.dll");
2- childForm childForm_2 = new childForm("Dll2.dll");
3- childForm childForm_3 = new childForm("Dll3.dll");
************
in childForm
***********
private string dllFileName;
public childForm(string FileName)
{
this.dllFileName = FileName;
}

[DllImport("generalDll.dll")]
extern static int OpenDll(string DllName);

private void MemoryShow_Load(object sender, System.EventArgs e)
{
OpenDll(dllFileName);
}

How to creat new DLL instance?
 
The one how need to back working with VB6 is you, before starting with your Jok.

Whatever. You NEED to learn English *a lot* better - simply 'getting by' is obviously doing you a disservice as other programmers aren't understanding your problems, or mistaking them for something much more trivial (as seems to be the situation in this case).

A lot of people take an instant xenophobic reaction to posts that start 'How to do xxxxx...?'
because asking 'How do I...? ' as 'How to...?' is the most common language mistake foreigners make. I just skip straight over them, thinking that I could make a reply, but the person on the other end wouldn't understand it.

The application I'm trying to do is already done in MFC.

I personally think MFC is a load of crap - I can't get over the fact that it's a huge, huge great load of code that actually *DOES* very little.
We have 4 DLLs each one have open/read/write/close


"open", "read", "write" and "close" are VERBS. That means they're a DOING word - they're ACTIONS. They can't be possessed. i.e., a DLL can't "have" open. A DLL might *DO* an "open" operation, but it doesn't *have* open.


but each one have it own protocol for example Read/Write from/to IO/Uart/SMBus,I2C,Memory.....
The C# application Import General DLL witch have get

The word "get" should almost never follow the word "have". It sticks out like a sore thumb and confuses the meaning of the whole sentence.
DLL name and creat new instance this new instance is saved in the general DLL variable.

This makes me think you're building your project to rely on a huge technical malpractice. What the HELL is a "general DLL variable"????

Each Form is same GUI but deferent execution In each one for example have Address = offset = 0x20 for example,
But the display value is deferents because each form shod read the value from deferents places , from IO,MEM,I2C,UART.....
and???


Thanks for helpping me , and belive me you need along time to do 50% of what I have already done

Ah but that's where you're wrong. Because I *wouldn't do* what you're doing, at least not in the same way.... certainly not with MFC. There's so many people writing stupid unnecessary network services and packet sniffers and all sorts of stupid crap network components, none of it's really necessary. They just like playing with networks - fine! but why pretend there's a big point to it? Why not just write a network game?
 
Back
Top