|
I have a byte[] that contains what in C++ would be this struct:
struct<br />
{<br />
unsigned type : 5;<br />
unsigned level : 2;<br />
unsigned bouncing : 1;<br />
unsigned emp : 1;<br />
unsigned isBomb : 1;<br />
unsigned shrapCount : 5;<br />
unsigned fireType : 1;<br />
};
Is there a way to make the byte[] into a class in C# without doing each member seperately with bitwise AND & shifting?
|
|
|
|
|
You might find the BitVector32 class useful to base your code off of.
You would create references to your types with the following code:
BitVector32 bv = new BitVector32(0);<br />
BitVector32.Section type = BitVector32.CreateSection(31);<br />
BitVector32.Section level = BitVector32.CreateSection(3,type);<br />
BitVector32.Section bouncing = BitVector32.CreateSection(1, level);<br />
BitVector32.Section emp = BitVector32.CreateSection(1, bouncing);<br />
BitVector32.Section isBomb = BitVector32.CreateSection(1, emp);<br />
BitVector32.Section shrapCount = BitVector32.CreateSection(31, isBomb);<br />
BitVector32.Section fireType = BitVector32.CreateSection(1, shrapCount);
The values are accessed as follows:
bv[type] = typeValue;<br />
bv[bouncing] = 1;
Access to your values with no &, |, or <<
|
|
|
|
|
|
for my current c# project i need a ftp connection test.
Given: Username, Password, port, hostname or ip
i tried it with System.Net.Sockets.Socket but it seems to be to slow to test more than 10 ftps in a row, cause of connection delay. the returnvalue just have to be boolean for Online/Offline
Somebody know a fast method to test this?
thanks / regrards
Martin Lierschof
Junior Programming Assistant
World-Direct.at eBussines Solutions GmbH
mail²: martin.lierschof@world-direct.at
|
|
|
|
|
I have an IIS-managed server object, exposed to clients using a service/wellknown web.config entry. But I don't want clients to have to know the type of the object (currently defined in a shared library) -- rather I want them to just query for the interfaces they require. This would theoretically allow me to change the underlying type on the server without code changes on the client.
To achieve this I wanted to expose the type as System.Object, but does not seem to be allowed by the remoting system. Have I made a design mistake? If so, what should I be doing?
Jade Burton
Programmer
|
|
|
|
|
You'll have to expose the object as atleast its interface.
<br />
public IMyInterface GetIt()<br />
{<br />
return (IMyInterface)myObj;<br />
}
where myObj is an object of any class that implements the IMyInterface interface
|
|
|
|
|
You might be able to use internal on all other classes except your facades/interfaces. That should 'hide' those classes from all outside calls.
|
|
|
|
|
If i create an array that is a specific size
int[] myInts = new int[10] but only fill the first 5 values, how can i reduce the length of the array to 5? so the following will happen
myInts[0] = 5;
myInts[1] = 4;
myInts[2] = 3;
myInts[3] = 2;
myInts[4] = 1;
for (int i = 0; i < myInts.Length; i++)
{
Console.WriteLine(myInts[i].ToString());
} and the output would only be 5, 4, 3, 2, 1 and not throw an exception since myInts[5] is null
|
|
|
|
|
hi,
if the size of the array is unknown before it is used then you must check each member of the array for null value.
Change tour for loop to this
for( int i = 0; i < nyInts.Length, myInts[i] != null; i ++ )
as i know there is no any function to resize of an array.
cheers,
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
If you need to resize an array, you should go throug the ArrayList, even though it isn't typed.
If you need a typed array, but don't know the size of it you can use ArrayList in this way:
<br />
ArrayList al = new ArrayList();<br />
<br />
al.add(5);<br />
al.add(4);<br />
al.add(3);<br />
al.add(2);<br />
al.add(1);<br />
<br />
int[] myInts = (int[])al.ToArray(typeof(int));<br />
If you need to change the size of the array, you can start with ArrayList al = new ArrayList(myInts); instead.
This will add some overhead (going back and forth between arrays and arraylists), but it gives you the type safety you need.
|
|
|
|
|
I want to make a trial version of my program, I want it to expire after 30 days, and if you want more you buy a serial number. (In other words; the usual.)
I know this is a very common thing but I've never done it before, can anyone point me to some tutorials or something about how to do this? I'm thinking I can make a win32 C++ dll and interop with it to avoid being easily decompiled, but I don't know how to get started with the s/n and expiration stuff.
Thanks
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Bog wrote:
I want to make a trial version of my program, I want it to expire after 30 days, and if you want more you buy a serial number. (In other words; the usual.)
I know this is a very common thing but I've never done it before, can anyone point me to some tutorials or something about how to do this? I'm thinking I can make a win32 C++ dll and interop with it to avoid being easily decompiled, but I don't know how to get started with the s/n and expiration stuff.
Sorry for not giving a solution to you: I think you won't have an easy solution. Protection schemes that use a separate DLL are simply not safe. What one normally needs to do is to create a dummy DLL and provide the application with it. Anyone capable of decompiling an app should be capable of creating such a DLL.
I too am looking for a good protection scheme for .NET but I was not able to find such a thing yet, even with hard locks involved.
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
A possible solution: encrypt the serial number with an asymmetric algorithm.
Even after decompilation, people will find the public key needed to decrypt the serial number but they will not find the private key needed to crypt it.
|
|
|
|
|
I've had this issue before.
Unless you want to pay out loads of cash for a protection package which will almost certainly get cracked you should just put some simple time expiry code in. Maybe add a time stamp to an innocent file somewhere or something.
The thing is in my experience, if you produce a nice little app and distribute it as a trial then get people to buy. Most people will- if it is a good application- pay the few quid to get the full version. The issue really is that if it is an app that is __so__ good that it becomes __very__ popular, it doesn't matter what scheme people use to protect it, it WILL be cracked and on Kazaa within 24 hours. (as with Windows XP, Office XP, PhotoShop, InDesign etc etc etc all cracked and shared despite the investment in copy protection and license enforcement!)
You can't win.
The only 98% way of securing the software is to use something like hardware dongling... but that's a different set of deployment scenarios.
|
|
|
|
|
|
I agree. Don't waste too much time in developing some "secure" serial number/trial version scheme. Better to spend that time making your application better. If companies like Microsoft, Adobe and Macromedia can't stop cracking/hacking, what chance do we have? If your software is any good it WILL be cracked one way or another.
-----------------------------
Try my Batch Image Processing Software Read my DirectX 8 Tutorials
|
|
|
|
|
The best protection I have seen was for Virtual TurnTables. If you tried to debug the exe, it would simply shutdown your system. But even that wont stop the crackers.
<a TITLE="See my user info" href=http:
|
|
|
|
|
when I added a report to my project, then packaged it.
On the client computer, I installed .NET Framework, then installed MDac2.7, finally installed my project, but when view the report, it's go to error!
maybe it's the license problem.
how can I solve this?
|
|
|
|
|
Crystal Report framework is different from .net framework and MDac. Go and see the CD that you used to installed .NET framework.(I guess its CD No.5 of Visual Studio.NET). You will see a separate directory that included Crystal Report Framework.
Mazy
No sig. available now.
|
|
|
|
|
hi,
thanks for your reply.
But I dinnot find any folder of your mean. Just thought when used Crystal Reports in our project, the setup project will detect the component of Crystal Reports and include it while you setup.
Would you show me the Crystal Report Framework folder or something like a file to setup CR Framework.
thanks again.
|
|
|
|
|
hi friends,
I am currently interested in writing a packet capture program like etheral. I finished the base api part. I used packet.dll source code of winpcap and ported all the function to c#. In other way , my api class doesn't use wpcap.dll and packetx.dll. i only use npf.sys ndis kernel driver. And then i downloaded etheral source code and added the ability of supporting over 15 protocols which are LLC , NETBIOS , IPX , STP , CDP , TCP , UDP , ICMP , HTTP , NBSS , NBDS , NBNS , ARP , EIGRP , DNS ( Not finished yet ) , LOOPBACK , SMB ( Not finished yet ) and SMB Mail SLot ( Not finished yet ).
Because it is very difficult to add so many protocols to my project and because it takes so much time, i need friends to help the project finished and to correct my bugs in the code and to recommend better methods that can be used in the code.
thanks for now,
sincerely yours,
Fırat Koçak
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
i have been given what seems like an imposible task of trying to read in an old random access file generated by VB6.. i have to parse out a ton of values out of this file, and to be honest i have no clue on if this is even possible..
here is what im doing currently:
FileStream aFile = new FileStream(m_strReportFilename, FileMode.Open);
byData = new byte[2];
aFile.Read(byData, 0, byData.Length);
int nInt = Convert.ToInt32(byData); this crashes on the last line with the error 'Specified cast is not valid '..
i have a listing of the structure of the file which consists of the following types: Integer , String (of set length), Currency (which is not a type in .NET), Boolean , and Date ..
i had it where i read in the whole file into a byte array to parse, but now im trying to just get the first integer out of the file.. can someone point me in the right direction please?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
hi,
i couldn't see any function call as you made. There is no any ToInt32 function accepting a byte array as a parameter. But i can suggest you a few way to do this.
But first you should correct the array length of byData to the value 4 ( for int values there needs a 4-byte space ).
Way 1 -
unsafe public static int AddressOf(byte[] variable)
{
int ptrptr;
fixed(byte* ptr = variable)
{ptrptr = (int) ptr;}
return ptrptr;
}
int byDataAddr = AddressOf( byData );
int * iValue = ( int * ) byDataAddr;
int nInt = *iValue;
Way 2 -
int nInt = ( ( int ) byData[3] ) << 24 + ( ( int ) byData[2] ) << 16 +
( ( int ) byData[1] ) << 8 + ( int ) byData[0];
there is a way more but not so important. those above may help you, i hope
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
thanks for the suggestion, i will try what you have suggested.. according to what ive been told an int in .net is 4 bytes, but in vb6 an int is 2 bytes, let me know if im mistaken.
thanks for the help, ill let you know how it goes!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
this has helped a bit with integers, but im having a hard time seeing how i would use either of these methods to read strings or bools, any suggestions?
thanks in advance!
still a newb.. cut me some slack :P
-dz
|
|
|
|