|
Sorry i had a typo... the code should have been
<br />
<br />
#region P/Invoke stuff<br />
[DllImport("ws2_32.dll")]<br />
private static extern short htons(short val);<br />
<br />
[DllImport("ws2_32.dll")]<br />
private static extern long htonl(long val);<br />
#endregion<br />
<br />
Chen Venkataraman
|
|
|
|
|
You have to declare them as a part of a class:
namespace MyNamespace
{
public class MyClass
{
#region P/Invoke stuff
[System.Runtime.InteropServices.DllImport("ws2_32.dll")]
private static extern short htons(short val);
[System.Runtime.InteropServices.DllImport("ws2_32.dll")]
private static extern long htonl(long val);
#endregion
}
}
They cannot be a member of the namespace directly (ie the following code will make the compiler barf in the way that you described)
namespace MyNamespace
{
#region P/Invoke stuff
[System.Runtime.InteropServices.DllImport("ws2_32.dll")]
private static extern short htons(short val);
[System.Runtime.InteropServices.DllImport("ws2_32.dll")]
private static extern long htonl(long val);
#endregion
}
--
Russell Morris
"So, broccoli, mother says you're good for me... but I'm afraid I'm no good for you!" - Stewy
|
|
|
|
|
duh... i gave up after struggling with it for a day. And i've done P/Invoke stuff before & usually could make sense of what the compiler thought was wrong - with this one, i just lost it! Silly me!
Thanks.
Chen Venkataraman
|
|
|
|
|
Hello all !
I am about to develop an application which purpose is to edit information of one or a couple of days...
Here is the approximative final look it should have :
Month --------Janvier----------- ...
Days --Mon--Tue--We--Thu -- ...
Day -- 01 -- 02 -- 03 -- 04 -- ...
Color --Bl -- Wh -- Gr -- Red--...
Price -- 12-- 10 -- 11 -- 12 --...
So let me explain a few things :
- each day is set in a column of a grid (separated by '--' here) and the day of week are drawn on a blue background whereas the WE are green
- please point out the first title column which will be always visible
- the column width is constant whatever the screen width and no scrollbar are visible so that we can browse throught days by clicking around on the calendar (first 3 rows) by implementing the onclick event
- No keyboard edition is allowed. The inputs are made by click or click&drag on the 2 last rows (color&price) depending upon a parameter box previously filled. Like painting on the calendar with the mouse if you see what I mean...
- No selection control should be visible on this grid
- The whole thing should be smooth enough to use for us to feel comfortable.
- the original datas are retrieved using a web service that returns a typed dataset with a row by date.
- another request should be made and datas should be added to the original datas
All that is very beautiful but... there are issues....
So here are my problems :
Should I use a datagrid with columnstyle or draw it by myself on a paintbox ?
What's the best way to implement the databinding between the retrieved dataset and the datagrid (in case I use a datagrid !!) which are reverse in fact (date in rows and date in cols) ?
In case I use a datagrid, should I bind a blank matrix to it in order to fix the number of rows and columns and draw the values retrieved from another dataset, or should I transform the retrieved from WS dataset for it to fit the datagrid orientation ?
Here we are for the moment...
If you have any suggestions or ideas on how to improve or implement my application, feel free to inform me !
Thank you in advance for all and have a good day !!!!!
Guim7
--diving in the abyss of C# and .NET--
|
|
|
|
|
Nobody has a clue ???
please help me!!!!
Guim7
|
|
|
|
|
Hi,
Does anyone know if it is possible to replace an existing COM server with a .NET server without having to rebuild the existing COM clients?
Any help or pointers would really be appreciated,
cheers
Jamie.
|
|
|
|
|
Someone here is very likely much more knowledgable about it... but I can say that it should not require a rebuild if the interface definition does not change. That said, however, I can't imagine you can keep the exact calling semantics between ATL COM or VB OCX and .NET. The types, if nothing else, will probably be different enough to cause a problem... maybe not. Try it. It shouldn't be difficult to code a minor test.
|
|
|
|
|
COM Callable Wrappers (CCW's) - check it out.
HTH
There are only 10 kinds of programmers - those who understand binary, and those who don't.
|
|
|
|
|
Hi All
What is nmake used for?? Can anyone give me an example for its usage ???
Thanxs
Maharishi
Nothing is Impossible. Even impossible spells "i m possible"
|
|
|
|
|
nmake is a build environment tool which uses a "makefile" to execute build instructions. The "makefile" contains variables and commands. Here you go: NMAKE Reference.
|
|
|
|
|
I'm writing a plug-in in VB.NET to a an application called DesktopSidebar for Windows. Right clicking my plug-in's "panel" shows among other things a Properties Dialog. All I need to do is pop up the dialog in the proper place and on the same monitor in a multiple monitor environment. My plug-in doesn't appear at this point to have the Window handle of the calling application. After quite a bit of trial and
error I came up with this:
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Int32,
ByRef lpRect As RECT) As Int32
Public Structure RECT
Dim Left As Int32
Dim Top As Int32
Dim Right As Int32
Dim Bottom As Int32
End Structure
Dim colProcess() As System.Diagnostics.Process
Dim oProcess As Diagnostics.Process
colProcess = Diagnostics.Process.GetProcessesByName("sidebar")
If colProcess.Length > 0 Then
oProcess = colProcess(0)
Dim handle As System.IntPtr = oProcess.MainWindowHandle
Dim loc As RECT
If GetWindowRect(handle.ToInt32, loc) > 0 Then
'Where are we docked?
If loc.Left = 0 Then
Me.Location = New Drawing.Point(loc.Right,(loc.Bottom -
loc.Top)/2)
Else
Me.Location = New Drawing.Point(loc.Left - Me.Width,
(loc.Bottom - loc.Top)/2)
End If
End If
End If
This works great as long as you have a single monitor, whether DesktopSideBar is docked to the Left or the Right. However, I run in a
multi-monitor environment. In my particular setup my primary display is my laptop and my secondary display actually hovers ABOVE my primary display (it's a 19 inch monitor) and I have my desktop extended onto it. The code above, only targets the primary display, even though I dock DesktopSideBar on my secondary monitor. My screen coordinates are still good... just not on the right monitor.
Could anyone offer up some suggestions on how to not only determine the monitor my panel is on, but also how to set the location of my dialog to a specific place on the proper monitor?
|
|
|
|
|
When running an application on a multiple monitor environment the coordinates of the form are the coordinates for the combined desktop.
The .NET Framework provides the Form.DesktopLocation property to set and get the location of forms in multimonitor environments. So, in the code you posted above you should remove stataments like
Me.Location = New Drawing.Point(loc.Right,(loc.Bottom -
loc.Top)/2)
replacing them with
Me.DesktopLocation = New System.Drawing.Point(loc.Right,(loc.Bottom -<br />
loc.Top)/2)
|
|
|
|
|
how to access web service with SSL from windows application (C#)?
How to use the certificate in the client windows application/
Is there any sample available?
Thanks a lot.
|
|
|
|
|
Hi!
I have the following:
function(Control theControl)
{
// At this point I know that the control has an items property
if (theControlis ListBox) ((ListBox)ctrl).Items.Clear;
if (ctrl is ComboBox) ((ComboBox)ctrl).Items.Clear;
}
You guru's probably already know my question...
How can I create a generic solution here?
something like:
function(Control theControl)
{
// At this point I know that the control has an items property
((theControl as Type)ctrl).Items.Clear;
}
|
|
|
|
|
What you need is an interface. If all Controls with .Items implemented a particular interface, something like IHasItems, then you could do a generic implementation. Unfortunately, there is no IHasItems interface, so you're SOL.
You could create a wrapper class around a Control, create an IHasItems interface and implement it yourself. For instance,
Define an interface like so:
public interface IHasItems
{
IList Items
{
get;
}
}
Then inherit a class from each control you need to use, while implementing that interface:
public class ListBoxEx: ListBox, IHasItems
{
...
}
That's it, you can then pass any IHasItems implementer into your function
function(IHasItems theControl)
{
theControl.Items.Clear();
}
Now, with that solution you're going to have to guarantee that the .Items property will return something with a .Clear() method, but you get the picture.
Hope that helps.
The graveyards are filled with indispensible men.
|
|
|
|
|
I just checked and the above solution will indeed work. However, that is quite a bit of extra work (you have to create an interface, then create a wrapper class).
Instead of that, why not just make your function accept an IList instead of a Control? For instance,
public void function(IList items)
{
items.Clear();
}
Then pass the items to it like:
ComboBox combo = new ComboBox();
ListBox listBox = new ListBox();
function(combo.Items);
function(listBox.Items);
That is an easier solution and will work equally well. If your function requires the Control, not just the .Items, then you should use the first solution I posted.
The graveyards are filled with indispensible men.
|
|
|
|
|
Hi Judah,
Thanks for your input. I'll try it out and see if that's what I need.
|
|
|
|
|
Both Listbox and ComboBox inherit from ListControl , so it would be somewhat logical to assume that's where the Items porperty comes from. If only it were that easy.
Although they share a common name, Items properties represent differents type of objects in Listbox and ComboBox (ListBox.ObjectCollection and ComboBox.ObjectCollection , respectively).
Therefore, there's no common ancestor you can cast to and call Items.Clear() .
As for your question of how to create a generic solution, there is a way, although it may be overkill for what you're looking for.
using System.Reflection;
object collection = ctrl.GetType().GetProperty("Items").GetValue(ctrl, null);
collection.GetType().GetMethod("Clear").Invoke(collection, null); Alas, the 'generic' solution is usually not the easiest
Charlie
if(!curlies){ return; }
|
|
|
|
|
Oops. Upon further reflection (no pun intended) and reading the other proposed solution, I realized that once
you've got your object collection, you can cast is to IList and call
Clear() on it. So the second line would become:
object collection = ctrl.GetType().GetProperty("Items").GetValue(ctrl, null);
((IList)collection).Clear();
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi Charlie,
This was what I was looking for!
Thanks a lot.
John
|
|
|
|
|
Hi,
I have a web app where I'm using SmtpMail to send individual messages when a request is made to a supervisor. It works ok, but the problem is that the web server is not the smtp server and relaying through the mail server (Lotus Domino 5) takes like , I'm not kidding, 4 - 5 seconds to execute the Send method! If I use the local IIS smtp server, and have it relay to the real mail server, the call happens instantly. I've tried pointing at another IIS smtp server on out network and again, it enters and leaves Send immediately. So my question is, what is Send doing with the Domino server that is taking so long? Has anyone had any experience with this?
|
|
|
|
|
Have you tried sending an e-mail with outlook though you Domino server to see how quick it is?
It could just be your setup.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Hi, I have a problem. On our computer (Celeron 566 MHz, 128MByte, W2000, .NET1.1) we use a CAN bus for getting measurement data from a client. For the CAN bus there is a DLL for NT/2000. Everytime if data comes in, the DLL calls a callback routine in my C# program. Data will come all 50 ms at the moment. This is working so far but if the data comes in, the CPU usage goes up to 100%, even if the callback routine in my C# program is doing nothing. That means only for calling the callback routine every 50 ms is killing the system. Is it possible that I'm doing something wrong?
Before we have written this software in Delphi and at that time the program needs only around 2%-5% CPU usage with 50 ms and around 10% with 1 ms data interval.
Regards
Michael
|
|
|
|
|
I think you'll need to post a little more information to get much help. That's a pretty difficult question to answer without code. Still, when you say CAN, are you referring to the bus protocol often used in automobiles, trucks, and various equipment? If so, who wrote your communications DLL? If it's what I'm thinking, you need to take a look at setting filters to limit the amount of incomming data. CAN data running at full speed (about 1 meg I think) is quite a bit of callbacks. If filtering isn't an option in the supplied DLL, you could write your own in ATL COM. This should be much faster and then you could post up only the messages you really need to your application. If we're on the same page, you may want to consider another provider for your communications DLL like possibly Noregon Systems out of Winston Salem, NC.
|
|
|
|
|
Ok, I will give some more info. CAN means the busprotocol which is used in automotiv industries. The DLL is written by the manufacturer of the industrial computer (using the Win DDK), where the CAN chip is build in.Of cause this is not only the DLL but also a system driver for this hardware. The DLL is only the interface. We used the CANbus with 250 kBaud which enables us to read the incomming Data with 1 ms resolution and we need all the data because we have to control a very dynamical process.
Next I will give some code how I have impleneted this:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Security;
namespace CanOpen
{
// First of all I define the data structure for the callback function
// Before this was public byte oldData[] and public byte newData[]
// But the structure of the Callback function works with byte oldData[8] and
// byte newData[8] and I didn't know how to realize this in C#
public struct NewDataType
{
public int node;
public byte oldData1,
oldData2,
oldData3,
oldData4,
oldData5,
oldData6,
oldData7,
oldData8; //
public byte newData1,
newData2,
newData3,
newData4,
newData5,
newData6,
newData7,
newData8; //;
public int dataLen; //max. 8 bytes (= max. PDO data length)
public PDOChannelType PDOChannel;
}
.....
// Next I define the delegate for the Calback function
delegate void DelegateUserCANNewInputData( ref NewDataType pNewData);
.....
// This is the function, which registers the callback function,
// I tried with and without SuppressUnmanagedCodeSecurity but it has no influence
[DllImport("canopen.dll"),SuppressUnmanagedCodeSecurity]
static extern int CANopenNewInputDataRegister(DelegateUserCANNewInputData
UserCANNewInputData);
.....
private void RegisterCallBackFunctions()
{
int RetCode;
DelegateUserCANNewInputData FptrUserCANNewInputData = new DelegateUserCANNewInputData
(UserCANNewInputData);
RetCode = CANopenNewInputDataRegister(FptrUserCANNewInputData);
}
|
|
|
|