|
You can declare C functions in C# using the extern keyword along with the DllImport attribute. Once the function is declared, you just call into it. For example:
using System.Runtime.InteropServices;
<P>
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);
<P>
MessageBox (0,"API Message Box","API Demo",0);
See the following and other articles on the topic:
http://www.thecodeproject.com/csharp/c__and_api.asp
There is no need for headers in C#. You just put all your code in the .cs class. You generally wrap your code within a namespace as a way of organizing things and to avoid name conflicts with other code -- it doesn't really correspond to a header.
|
|
|
|
|
I am not using any C functions from any dll.
Actually i have a packet driver library (which is completely written in C). I want to use this library from a C# file.
I have the source code of the library, so, I have to supply header files definitions of 'structs' used in function calls and these function calls are linked statically.
Simply i want to use the library from a C# file as i use it from any other C file.
Tell me if i m unable to explain my question or some extra details are required.
regards.
|
|
|
|
|
If this library has only a few entry points, then it's worth using P/Invoke to use it from C#.
If the library has many entry points, or requires a significant amount of structure marshaling, then use MC++ instead. With MC++, you can mix managed code and native code without reexposing signatures.
|
|
|
|
|
thanks
as it came to me, i switched to visual C++ .net. I am now able to mix the unmanaged code of the library and the managed code of .net. It is working nice.
But can you give me some favour by telling that whether there is any "Network packet capture" support in .net library? Any namespace, classes etc.
|
|
|
|
|
hashimsaleem wrote:
But can you give me some favour by telling that whether there is any "Network packet capture" support in .net library?
Although the System.Net.Sockets.TcpClient wraps sockets to read/write packets, I believe this is not what you are looking for. I believe that what you need is at a lower-level, much like "Network adapter" and, at this point, there is no better substitute than the Windows DDK (plain WIN32 C code, as you may know).
|
|
|
|
|
I've tried to get an example of a simple (Drawing Background, Text, FocusRectangle) owner draw ListVIEW but couldn't get one. There are some example with the UtilityLibrary which do not work or are hopeless complicated because of overloading its possibilities.
Is there anybody who knows where I can get a working example of a C# Owner Draw ListView Control?
I would be extremly happy to have one!!! (Ein Königreich für ein Owner Draw ListView)
Any hints for WndProc would be help.
Thanks!
Stefan
|
|
|
|
|
In windows XP there is a feature "Group similar Taskbar buttons"
How I can set the icon and title for taskbar button for my application's grouped windows.
Sonork ID 100:25668
|
|
|
|
|
I have a program written in C#/VS.NET and I am trying to find out how much memory a specific instance of class is using during runtime. Does anyone know if there is a feature in the VS.NET debugger that would let me know this information? Or, do you have any ideas on how I could get an accurate estimate of it's size?
FYI: Monitoring the "Perfomance Tab" of the "Windows Task Manager" is not accurate enough for the information I am needing.
Mark Sanders
sanderssolutions.com
|
|
|
|
|
The .NET framework sdk comes with a full fledged memory/usage/load profiler. <framework SDK folder> \ tools developers guide \ samples \ profiler.
|
|
|
|
|
Hey All,
I was wondering if anyone out there is using and has suggestions for 3d party control packages. Ive seen a couple out there, like infragristics, has anyone used them?
Thanks for the suggestions,
Ryan
|
|
|
|
|
I've been using quite a lot of 3rd party controls. Here are some impressions:
- Infragistics: I've been using their ActiveX components in VB6 and they work pretty good. When we switched to C# we got their NetAdvantage Suite (ActiveX, .NET and ASP.NET) and I must say the .NET controls are pretty unconsistant in use (properties, collections, methods are not always the same between similar controls. There still are quite some bugs/weird things but I'm overall quite happy with them. They also have a great support. If you want to use these don't forget to buy the .NET-sources also, I regret not having done so.
- Janus Systems: I had all my VB6 apps based on their grid but it took them too long to move to .NET so I switched to Infragistics. Took a look at their .NET grid and it still looks pretty good.
- Xceed SmartUI.NET: just got them as a free upgrade from my Sax SmartUI.NET (which wasn't too good, I saw it as a waste of money). The new version seems more stable but I haven't had any use for them right now.
- Developer XPress XtraNavbar: Pretty nice and easy to use Outlookbar-like control with extra's.
In my applications I'm using currently MagicLibrary, Infragistics and XtraNavBar along with some specialized controls I developed my self based on the Infragistics controls.
Hopes this helps
Stefan
|
|
|
|
|
i am currently doing something like the following to a combobox:
(for int i = 0; i < 10; i++)
{
MyObject objData = MyData.GetAt(i);
this.cbMyComboBox.Items.Add(objData.strWord);
}
which adds the text to the combobox fine.. but what i really wanna do is set a data value for each item i add.. there are 'tag' values for tree controls, but i dont see anything like this for the combobox.. and if i just add the object then it displays the object type because it doesnt know what text to display..
im sure this is a common problem, just couldn't find the answer in the message boards..
thanks in advance!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
well one thing you could do is override the tostring method, and throw your own variable in there that would add some meaningful text, have you tried that?
Ryan
|
|
|
|
|
that would require me writing a class derived from combobox that was familiar with class i was adding to the combobox.. so it would work, but only for one type of class.. i dont understand why there is no tag property for the items..
c++ would be like:
for (int i = 0; i < MySet.GetSize(); i++)
{
MyObject* pObj = MySet.GetAt(i);
int nPos = MyComboBox.Add(pObj->m_strText);
MyComboBox.SetDataPtr(nPos, pObj);
} that way when i handled the selection changing i could have a pointer instantly to the item it was changed to.. ah well..
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
if i understand correctly, your trying to get text from objects that you add into the combo box. All objects in c# support the tostring method, it is a method of the base class, so you wouldnt have to do any extra inheritance.
|
|
|
|
|
AAAAAH.. i see what your saying..
sorry im a bit slow sometimes.. i guess that makes perfect sense, thanks!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
well, i thought this would work, but it doesnt..
this.cbCountyDefault.BeginUpdate();
for (int i = 0; i < m_saCountyRecords.Count; i++)
{
GASTCountyRecord objRecord = (GASTCountyRecord)m_saCountyRecords[i];
this.cbCountyDefault.Items.Add(objRecord);
}
this.cbCountyDefault.SelectedIndex = 0;
this.cbCountyDefault.EndUpdate();
MessageBox.Show(cbCountyDefault.SelectedItem.ToString());
MessageBox.Show(((GASTCountyRecord)this.cbCountyDefault.SelectedItem).ToString()); the first messagebox shows the objects name, and the one where i cast it shows the corect name..
the listing in the combobox lists the class name because it populates this by calling Object.ToString() not by casting it to my object type then calling ToString() .. any other suggestions?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
hrm.. it was how i was doing it.. ill put this here for future reference
how not to do it:
public class GASTCountyRecord : object
{
public string m_strCode;
public string m_strName;
public GASTCountyRecord(string strCode, string strName)
{
m_strCode = strCode;
m_strName = strName;
}
public string ToString()
{ return m_strName; }
}
how to do it:
public class GASTCountyRecord : object
{
public string m_strCode;
public string m_strName;
public GASTCountyRecord(string strCode, string strName)
{
m_strCode = strCode;
m_strName = strName;
}
public override string ToString()
{ return m_strName; }
}
thanks for all your help.. i think the way they have you implement this is a bit wack tho
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Hi.
WYSIWYG HTML Editors for webbased content managment systems have been around quite some time now. Personaly i love the free ASP.NET web control named "FreeTextBox", witch can be found at: SourceForge[^].
These days when more and more developers keep focusing on the power of the rich client, a HTML Editor Control for windows forms would be greate.
I was wondering if there where such a control around, where you could set up your buttons (witch type of HTML you would allow the user to create) and simply extract the html content. Are there inbuilt functions doing this in the RitchTextBox control?
-Jonas
|
|
|
|
|
Hello,I have got the appletElement by following:
mshtml.HTMLObjectElementClass applet=(mshtml.HTMLObjectElementClass)applets.item(i,i);
string altHtml=applet.altHtml;
to extract all anchors from the applet, a way is to process altHtml,I wonder whether has another way.
Thanks.;)
|
|
|
|
|
How do I detect when a dail up (or some other form of internet) connection is established?
|
|
|
|
|
I don't know the .NET BCL way to do it, but you could use InternetGetConnectedState[^] API. You can use it to find out whether you're connected, and what type of connection is currently being used (dial-up, LAN, whatever).
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
As part of my app, i've used reflection to load an assembly.
Assembly.LoadFrom(filename);
This works great. But I don't want the assembly to be bound any longer. I wish to modify/move/delete the assembly from the app. but now its bound and can't be modified.
Is there a way to 'unbind' an assembly?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
You would have to load it in a separate AppDomain. Then when you unload the AppDomain, it'll unload the Assembly.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
Right, firstly thanks for replying, it seems like the right was of doing it and after a bit of MSDNing, i've come up with some AppDomain code.
AppDomain appd = AppDomain.CreateDomain("Plugins");
foreach(Plugin File.....)
{
Assembly a = appd.Load(fileName);
}
OK this isn't all the code but its the only code that is failing. Basically the appdomain isn't loading the files. It throws the following:
File or assembly name <path>\plugins\Plugin.dll, or one of its dependencies, was not found.
For each of the plugin files I try to load. Now when it was trying to load the files in the main appdomain, it loads them fine, but now after trying what you said, I can't get it to load them. They are not bound anywhere else and the full path is given to the appd.Load() method.
Any ideas?
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?" - Anon
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|