|
Rüpel wrote:
but in the foo-call is to be inserted uswell.
oops , happens when u write the code out of your head straight into the textbox
Rüpel wrote:
2. no, the copy-call was ok, since the size-field is included (i.e. the value is at least 2 for the 2 size-bytes)
But wont the fist 2 byte values (being a size value) affect the byte[]?
(oops another typo , meant to do this)
byte [] message = new byte[size - 2];
Marshal.Copy(messagePtr,message,2,size);
or
byte [] message = new byte[size - 2];
Marshal.Copy(new IntPtr(messagePtr.ToInt32() + Marshal.SizeOf(typeof(byte))*2),message,0,size - 2);
I'm just interested
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I want to know wheather we can write components using c# in place of ATL COM.i.e..is it possible to write everything whatever we do in ATLCom.
|
|
|
|
|
It depends if you intend to consume these components from unmanaged or managed code.
If that's managed code, then you are talking about the whole .NEt platform. A C# user control exposes interfaces that can be used in a VB.Net class.
If that's unmanaged code :
You'd better have good reasons to do so. ATL/COM components do not require the .Net framework to work.
And yes, there are tutorials about this in MSDN. You usually end up by doing a tlbexp.exe or regasm.exe (which is the opposite of importing a COM type-library).
And I swallow a small raisin.
|
|
|
|
|
If I want my AP be only one ? How can I do this in C#?
There is an example in VC http://www.codeproject.com/threads/singleinstance.asp
|
|
|
|
|
VC apps usually take advantage of mutexes. Go in the .Net framework MSDN doc, search "Mutex". Finish the implementation.
And I swallow a small raisin.
|
|
|
|
|
When I saw this, I immediately thought of 'Highlander'.....
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
|
|
What do you mean by "doesn't like"?
Paul
|
|
|
|
|
it does not compile, as the function definition is as follows.
ChangeDisplaySettings(ref DEVMODE d, int flags);
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
DEVMODE is a struct.
1. just make another definition
ChangeDisplaySettings(object dummy, int flags);
or
2. change DEVMODE to a class with a sequential layout. Then you can pass null.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
I sent you VS solution, that happened to me too, seemed to be due not changing the enum declaration from ref DEVMODE to just DEVMODE ,its a class now so we dont need to. I however had to add the OutAttribute the the declaration.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
How about making the function unsafe ?
Then use a pointer as parameter.
But that's maybe not possible when it's an imported function!?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
have geen trying to get he current displaymode but have been unable, my latest attmpt was to try[^] and convert this articles code, but i had a little difficulty. I found the content of the DEVMODE struct on MSDN and put it into my code. I declare the EnumDisplaySettings like this
[DllImport("User32.dll")]<br />
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, DEVMODE lpDevMode);
then use it in code like this:
DEVMODE dm = new DEVMODE();
EnumDisplaySettings(null, -1, dm); but i get the exception 'object reference not set to an instance of an object' yet clearly, a DEVMODE object has been initiated.
any help would be appreciated.
*sudden thought* in the decleration of the DEVMODE struct, on MSDN, a couple of the members where of tpye TCHAR , declared like this.
TCHAR dmDeviceName[CCHDEVICENAME];<br />
TCHAR dmFormName[CCHFORMNAME];
i couldnt find what CCHFORMNAME is so i just used the MarshalAs Attribute like this
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
public string dmDeviceName; for both, could that be the problem?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
I think the exception lies with string lpszDeviceName being null.
You mite want to redefine:
[DllImport("User32.dll")]
public static extern bool EnumDisplaySettings(StringBuidler lpszDeviceName, int iModeNum, DEVMODE lpDevMode);
Then when calling do StringBuilder devname = new StringBuilder( insert const size here).
Also , many times you need to set the size of a struct. In this case, according to MSDN, you will need to.
Nnamdi Onyeyiri wrote:
i couldnt find what CCHFORMNAME is so i just used the MarshalAs Attribute like this
This you will find the value in the header files, so download the Platform SDK if you dont have it already.
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
I think the exception lies with string lpszDeviceName being null.
i dont think so, i tried entering a value for that, and it did not work, it gavethe same exception. i used null, because that is what was used in the article i gave the link for.
leppie wrote:
This you will find the value in the header files, so download the Platform SDK if you dont have it already.
is that installed with the default settings for vs.net install?
leppie wrote:
Also , many times you need to set the size of a struct. In this case, according to MSDN, you will need to.
i didnt know about this, ill have a look now.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Nnamdi Onyeyiri wrote:
dont think so, i tried entering a value for that, and it did not work, it gavethe same exception. i used null, because that is what was used in the article i gave the link for.
Still try using StringBuilder as u CAN pass null as a value.
Nnamdi Onyeyiri wrote:
is that installed with the default settings for vs.net install?
If u install VC++ , else just look for a dir in program files with many *.h files
I had a look and that is a pretty viscious struct . Im not sure what a BCHAR is though. Im gonna try do something in C# and see what i come up with. Can you perhaps mail me what u have done so far?
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
DEVMODE dm = new DEVMODE();
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
int mode = 0;
while (EnumDisplaySettings(null, mode++, ref dm) != 0)
{
Console.WriteLine("{0}x{1}, {2}bits {3}hz",
dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel, dm.dmDisplayFrequency);
}
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int EnumDisplaySettings(StringBuilder devname, int mode, ref DEVMODE devmode);
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public short dmOrientation;
public short dmPaperSize;
public short dmPaperLength;
public short dmPaperWidth;
public short dmScale;
public short dmCopies;
public short dmDefaultSource;
public short dmPrintQuality;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
}
This works Note the union ???? looks like it combines 2 int 's ???
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Im not really sure what a union in C++ does, it appears to join 2 variables into one, hence the commented dmNup. Can anyone C++ person please explain this in C# terms?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
A union uses the same piece of memory for two different variables.
For example
struct INTCHARS
{
char hi;
char midhi;
char midlo;
char lo;
};
union FOURBYTES
{
INTCHARS ch;
int i;
};
FOURBYTES four;
four.ch.hi = 1;
four.ch.midhi = 1;
four.ch.midlo = 1;
four.ch.lo = 1;
four.i = 0;
Now each part of four.ch is 0.
Going back a while since I used one of these.
Paul
|
|
|
|
|
Thx,
From what i can see is that unions are class like structures in a struct or class allowing easy retriaval/setting of inner variables. I have been using SequintialLayout classes todo this. Im not sure if we are talking the same thing, but I guess thats why the are not included in C#.
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
The big difference between a union and a struct is that changing one inner variable in a union will change all of them because they share the same space in memory.
As C++ came into play, unions became less useful, classes and pointers could be used to the same effect.
When PCs with more than 50 bytes of spare memory came out, unions again lost some usefulness.
Likewise properties haven't done unions any favours, you can now reference the same variable in different ways through get/set properties.
So I wouldn't be surprised if C# didn't have an equivalent, though there are times when it wouldn't go amiss.
Paul
|
|
|
|