how can i get a memory address of dll in C# program?
how can i get a memory address of dll in C# ?
Collapse
X
-
A dll is a Dynamic-link library. It does not have a memory location. When you use the dll in your application, memory will be used for the variables etc that the dll uses.
With this in mind, please explain your problem again because your question does not make sense.
-Frinny -
If void Set(char x) is C# then it does not have a constant address in the memory. The .NET garbage collector will move it around memory and you cannot assume that it will be at one location. There is a way to lock position of the variable in the memory and get its real address using Interop functions.
Can you describe your task more clear?Comment
-
the task is to pass a char between C program and C# program in real time
using DLL.C & C# are not the same.so C would store at memory location
different than the C# each time i load the dll.
so in C# rather then loading the dll and calling the function get to get the char.i
get the address of that char that C has stored it.Comment
-
If you are running two different programs then you cannot access memory of one program from another. This is basic protection mechanism of OS. One program does not have access to the memory of other program, whatever you do. In addition each program has its own address space. It means that some address can point to two different values in the memory in two different programs. Thus, an address of variable in one process points to absolutely different value in other process.
When you start some program Windows creates address space for it and all processing happening in that address space. Then you close program and windows delete everything related to your program from the memory. No way to leave something there. When next program is started it has access to pure clean memory.
As for me simplest way to communicate between processes is TCP/IP. Processes can communicate with each other over TCP/IP network protocol.Comment
-
Please let us know if you really have two separate programs that have to communicate with each other. Or is it some other case? Do you need to load C library into C# program and work with it from C#?Comment
-
When you start some program Windows creates address space for it and all processing happening in that address space. Then you close program and windows delete everything related to your program from the memory. No way to leave something there. When next program is started it has access to pure clean memory.
i want the access to be at the same time.
C program sets value and the C# program gets that value at the same time
(real time).That means the memory is not empty right ??Comment
-
I'm sorry to tell it to you. You cannot read memory from other program. This dead end. This function of CPU and OS to isolate process memory.
If you need to exchange data then you need to utilize some other approach than direct memory access.
Did I answered you question?Comment
-
You can. But you said that your C and C# are separate applications. By loading DLL of another application in your C application you will execute a copy of that DLL. It will not affect other already started application with the same DLL.
DLL is just a list of commands for processor. You can load and execute it within any number of application. Each time it will be loaded in particular process memory and all variables will be saved in that memory. Each time it will be separate.
If you a really have two application (two exe files) than you cannot load libraries of one into another to make them communicate.
If you actually have C program and C# dll that performs some operation you need then you can load it into C program. It is cold CLR hosting.
You can find documentation here.Comment
Comment