|
Hello Friends,
Can anyone give me the code example of calling C++ dll functions from C#.
Thanks in advance.
Pranoti
|
|
|
|
|
|
Hi Rupel,
Thank you for quick reply. I've seen the thread suggested by you and has implemented in the same way.
Basically the function contained within the dll is:
IOAPI bool IsCardInserted(void);
And I have exported this function from IoApi.dll.
So I did in this way :
[DllImport("IoApi.dll")]
private static extern bool IsCardInserted();
But I'm getting "System.DllNotFoundException : Unable to load DLL."
I've placed the 'IoApi.dll' in the same folder from where I'm calling it.
Could u please tell me where I'm going wrong.
Thank you.
Pranoti
|
|
|
|
|
The C++ dll has to have extern "C" or the name of the function
is decorated. You can find the name by using depends.exe or
dumpbin -exports ioapi.dll or link -dump -exports ioapi.dll
Or you can use the follwing:
[DllImport("IoApi.dll",EntryPoint="IsCardInserted",
ExactSpelling=false,CallingConvetion=CallingConvention.Cdecl)]
private static extern bool IsCardInserted();
|
|
|
|
|
With <<tlbimp quartz.dll="" out:quartztypelib="">> I get use of the DirectShow Interfaces.
I added the QuartzTypeLib now to the references of my c# project.
<<
QuartzTypeLib.FiltergraphManager graphManager = new QuartzTypeLib.FiltergraphManager();
QuartzTypeLib.IMediaControl mediaControl = (QuartzTypeLib.IMediaControl)graphManager;
mediaControl.RenderFile(filename);
mediaControl.Run();
>>
This works fine.
But why cant I get the IMediaSeeking Interface ?????
It seems not to be in the QuartzTypeLib ?????
With C++ its no problem, but with c# I cant get it
Have anybody got an idea ?
Thanks
PS: Are there tutorials , how to use the DirectShow with c# (the offical way)
|
|
|
|
|
i think we are all eagerly waiting for Managed DirectX 9 wake me when they release it
READ MSDN
|
|
|
|
|
Hi all,
I use property grid to display the properties of my object. But there are some properties should not be appeared depend on their values. Thus it isn't able to hard-code the Browsable attribute as "true" ([Browsable(true)]) or "false" ([Browsable(false)]) on these properties. I consider that I have to make an own attribute which does something likes Browsable attribute. But now I don't have any ideas to implement this class.
If you found out the way to solve this issue, please let me know. Thanks for your helps so much.
|
|
|
|
|
a) I have no idea.
b) Here's a link to some property information, hope it helps a tad.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/vsnetpropbrow.asp
|
|
|
|
|
How would I go about setting up a wall between a program and the internet, I want to intercept a email message before it leaves my computer, inspect it, then forward it to the smtp. It would be nice to do the same with ICQ, AIM, etc... is there a easy way to maybe stand in the way?
Lets say program A establishes a socket with program b (on computer b).
program A then goes to send information to program b. What I want to do is have program c (on the computer program a is running on) get the packet instead, so it can ask me if i really ment to send it etc (stop stupid macro virus).
Is there a easy way to do this, or is it super-crazy-complicated?
|
|
|
|
|
An easy way that comes to my mind is to create a server that listens on port 25 (SMTP)
Configure your mail client to connect to localhost, instead of the actual IP address of the SMTP server. Then each time you want to send an e-mail message it goes through your server first and then if it's ok forwards it to the real SMTP server.
But this only works for connections to one port
Regards,
Venet.
--------
Black holes are where God divided by zero.(Steven Wright)
|
|
|
|
|
I know I can simply use the program like a proxy, I guess I was hopeing to let the email program run without the program running, but be able to turn it on if I wished to.
How do firewalls do it? I bet its really complecated and on the hardware level.
|
|
|
|
|
Is anybody know how to implement a Custom Web Control?
Thanks in advance.
|
|
|
|
|
Hello,
I have been trying to figure this out all week. Does anyone know how to clear out a checkbox on a listview? By listview, I have a developer a program that looks very similar to BackupExec or any other backup software program. When you have selected a particular foler it goes and grabs the files that pertain to that folder. Does any know how I can get this to clear. I want to hook this up to my cancel button. Any help would be appreciated. Thank you.
cAptHiDDeN
|
|
|
|
|
I have tried three method:
public class Factory
{
public Factory()
{
//
// TODO: Add constructor logic here
//
}
public DataInfo CreateDataInfo1( DataInfo di )
{
if( di == null )
{
di = new DataInfo();
di.DataName = "Factory create";
return di;
}
return di;
}
public DataInfo CreateDataInfo2()
{
DataInfo di = new DataInfo();
di.DataName = "Factory create";
return di;
}
public DataInfo CreateDataInfo3()
{
return new DataInfo("Factory create");
}
}
All of them can work!
But I think 2nd and 3rd cannot work because the object will be reclaimed, i'm right?
Annex:
DataInfo class:
public class DataInfo
{
public DataInfo()
{
//
// TODO: Add constructor logic here
//
}
public DataInfo(string name)
{
//
// TODO: Add constructor logic here
//
this.dataName = name;
}
private string dataName;
public string DataName
{
get
{
return this.dataName;
}
set
{
this.dataName = value;
}
}
}
Demo:
public static void Main()
{
DataInfo di = null;
Factory f = new Factory();
di = f.CreateDataInfo1(di);
if( null!= di )
Console.WriteLine( di.DataName );
di = null;
di = f.CreateDataInfo2();
if( null!= di )
Console.WriteLine( di.DataName );
di = null;
di = f.CreateDataInfo3();
if( null!= di )
Console.WriteLine( di.DataName );
}
Thank you for your help!
I'm amumu, and you?
|
|
|
|
|
My (very new) understanding of C# is this:
In CreateDataInfo2 you are instantiating the object DataInfo() and assigning a reference to it in the local DataInfo di. Therefore the reference count to this object is one. Whe you are return the reference and assign it to another DataInfo object in Main(), the reference count goes to two. Now, the local variable in CreateDataInfo2 goes out of scope, and the reference count to the di created in that method goes back to one. So the count of objects referencing the DataInfo is still one, and therefore the object is not released.
The same applies to CreateDataInfo3, except is a simpler case.
Is this right, anyone?
Marc
|
|
|
|
|
I think you are right, thank you very much!
I'm amumu, and you?
|
|
|
|
|
No, no, no, no, no, no! :P
There is no such thing as a reference count in .NET (aside from COM Interop anyway). I highly suggest reading the Garbage Collection article in the .NET section of this website, I learned a lot by reading it.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
I did read it. It seemed to me that it talked a lot about keeping track of memory references, etc. I learned a lot too, reading it.
OK, could you be a little less obtuse and tell me why I'm wrong?
Thanks,
Marc
|
|
|
|
|
You mention that it keeps a reference count, perhaps I shouldn't point this out as being wrong; but more of the mind set it puts you in with throwbacks to COM and VB style deterministic finalization.
Now the count isn't what is important; it is whether or not any reachable reference exists. If the count was important there would be problems with circular references.
That is why I flagged it as being incorrect
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Ah. A subtle difference.
I wonder what the actual implementation looks like. In the article on garbage collection, Chris wrote:
"...It then lists all your application's global and static memory pointers, local or parameter variables and CPU registers containing references to objects on the heap, and then uses these objects to build a graph of all objects on the heap that are either directly or indirectly referenced by your application. Any object on the managed heap that can somehow be accessed by your application will be marked. There are optimisations in place to remove the possibility of circular memory references causing infinite loops, and to ensure that chains of references are only processed once.
The GC then compacts the heap by moving non-garbage items together...In doing so the GC is also responsible for updating the values of all pointers into the heap, so that references to objects on the heap that have been moved are still valid."
(Sorry for the long quote).
The interesting thing here is that the GC has to go back and "fix up" all references to non-garbage items. So it must maintain a list of fix-ups, which means that a count should be easily obtainable. It has to iterate through a list somehow.
Anybody have source code to the GC?
Marc
|
|
|
|
|
Marc Clifton wrote:
Anybody have source code to the GC?
I have the source to a GC, but I don't think its the same implementation that MS used. Its included with the Rotor project's source code.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
I'v read the msdn about garbage collection, it doesn't tell us what way microsoft use to keep reference information of the object if the object hasn't a Finalize method.
Am I right?
I'm amumu, and you?
|
|
|
|
|
Logic would dictate that it should work similarly; but there isn't as much overhead involved with a class that doesn't have a finalizer. My guess is that it still keeps track of what is reachable; but when it performs the garbage collection it will free up the memory then instead of placing it in a queue to be dealt with by a finalizer thread.
Only a guess though
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Forget it.
Now one thing we can be sure that Method 2nd and 3rd are all make another reference to the object created in CreateXXX, right?
I'm amumu, and you?
|
|
|
|
|
Actually you won't need to make a reference in the 2nd and 3rd methods because of the way it works underneath it all. When you go to return the value a reference to it is placed on the stack; so there is still a reference to the value.
Now when the reference is assigned to the variable it is popped off the stack and you now have the reference stored in another place.
If that makes any sense to you; I'm having a hard time coming up with clear thoughts on it myself.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|