|
What? I said Joshua, not HAL.
|
|
|
|
|
You need to get some books on databases and start reading...
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Store them where? In memory, database, text file, ...
Display them how? On screen, console, printer, ...
Try and describe your problem in clearer terms.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
For loading a file that was originally written by an application written in C++, I have been declaring each part of the file as a struct, and converting the data into a struct using this function:
public static TStruct GetStruct<TStruct>(byte[] data,Type t)
where TStruct : new()
{
int structSize = Marshal.SizeOf(typeof(TStruct));
TStruct outstruct = new TStruct();
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
outstruct = (TStruct)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),t);
handle.Free();
return outstruct;
}
This works fine for structs that do not contain arrays or that contain only arrays that can be defined using fixed (eg fixed int someVariable[10]; works fine) ,but I run into a problem when I want to do this to a struct such as:
struct Foobar
{
int count;
customStructType someStruct[count];
}
I've tried using [MarshalAs(UnmanagedType.<tried all these>, <parameters specified type takes here>)] but it either requires me to specify a fixed number upfront or causes my GetStruct method to give me an error that it "could not meaningfully obtain the size of the struct". LPArray allowed me to specify a particular element in the struct that acts as the number of elements in the array but that gave me the aforementioned lack of meaningful size error. Is there any way to make this work?
|
|
|
|
|
Nasty one. AFAIK .NET does not allow any direct coding that will create a structure whose length is not fixed at compile time - and I can understand why not.
I haven't tried it, but this[^] appears to address the problem. In a suitably nasty way, of course...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi everyone..
I am getting the above error in one of the application on this portal.
The application is:
http://www.codeproject.com/KB/IP/CSNetworkSniffer.aspx?msg=3625563#xx3625563xx
I am really new to socket programming so i need your help
Thank you and any help would be appreciated
|
|
|
|
|
Try posting your question in the forum at the end of the article, and then the author should get notified.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
It uses raw sockets to sniff TCP/IP, which cannot be done in Windows XP SP2 and above for security reasons. If you want to run this code, you'll need to do it on Windows Server 2003 and above.
From MSDN on Raw Socket limitations:
On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:
•TCP data cannot be sent over raw sockets.
•UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
•A call to the bind function with a raw socket is not allowed.
These above restrictions do not apply to Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.
|
|
|
|
|
This is my scenario: I have a huge database and I'm building numerous services to access the data.
Each service exposes a unique set of data and services to the consumer.
So for an object such as Company our internal service needs the raw address in the composite. However our portal service need fully enumerated Address info in the composite.
I wanted to avoid having a massive object with various composite addon's that don't apply to a given object but I'm running into difficulties.
First I decided that each composite builder class will be in a namespace deeper than the data namespace. So instead of myApp.Data it would be myApp.Data.Mainservice and myApp.Data.Portalservice for the composite objects.
My next step was to inherit Company, add a constructure that takes Company as input to populate internal fields, and add the DataMember for each Composite that is needed. Works great but I get a runtime error that I cannot inherit an object that is not marked as Serializable or DataContract.
Initially I just added a public partial class Customer and added the DataContract attribute, but that does not expose the DataMembers inside of the object.
I also cannot use the partial class definition as I need to be inside the namespace of the Customer object which puts me back into the same problem of having an accumulation of composite objects.
For those who need pictures here is the code I want to implement:
namespace Company.Data.InternalServices
{
[DataContract]
public sealed class CompositeLocation : Company.Data.Location
{
[DataMember]
public Address LocationAddress{get;set;}
}
[ServiceContract]
public class InternalContract:IInternalContract
{
[OperationContract]
public CompositeLocation GetLocation( Guid LocationIdentity );
}
}
namespace Company.Data.Portal
{
[DataContract]
public sealed class CompositeLocation:Location
{
[DataMember]
public EnumeratedAddress{get;set;}
}
[ServiceContract]
public class PortalContract:IPortalContract
{
[OperationContract]
public CompositeLocation GetLocation(Guid LocationIdentity);
}
}
When no method returns a Location, WCF drops the DataContract for Location. I want to force it to keep Location as a data contract!!!
|
|
|
|
|
I have a software which requires activation. I am going to save the user registration data on my sql server database on my host (online) via the WinForm registration form.
DO you recommended to do a normal sqlConection from the WinForm to the sql server online to syore the data?
or it's better to develop a web service for that?
what do you think?
|
|
|
|
|
Web Service
You should never expose the SQL server to public access outwith a private network unless you really really really must....
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
I wonder why not?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Yeah, it is all too dogmatic for me, resulting in loads of unnecessary complexity.
Just put the database layout, username and password on the web site. Keep it simple.
Or skip the whole activation thing.
|
|
|
|
|
Username and password will do - you can query the table structure from the DB.
I wonder why Microsoft don't do that?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
As DaveAuld says, go for the web service.
Presumably, you are using software activation as a way of securing your income and preventing piracy. If you expose your sql connection publicly so the WinForm app can access it, do you think that helps? Or creates a big security hole for naughty people to jump right through and pre-activate as many copies as they want?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Is there any way to assign an object by address in C#? (I want to use the word reference but it complicates the question). It's like you can have reference behaviour through functions that you cannot have WITHIN the function.
Example:
private MyClass m_MyClass;
public void MyFunction(ref MyClass objIn)
{
objIn = new MyClass() //Creates a new object in the function that called this procedure
}
But if did
private MyClass m_MyClass;
public void MyFunction(ref MyClass objIn)
{
m_MyClass = objIn;
}
public void SomeOtherFunction()
{
m_MyClass = new MyClass() //Now the calling function's object is forever unlinked
}
My question is:
//Is there some way to do something more like
m_Myclass = ref objIn; //????
I thank everyone who wants to be helpful but I am not looking for a workaround, I am trying to advance my understanding of .NET. Thanks again, All.
|
|
|
|
|
Ummm... what? It's hard to read that code; put it in pre tags (select it and click code block ).
thenutz72 wrote: It's like you can have reference behaviour through functions that you cannot have WITHIN the function.
C# (.net) is all about references.
thenutz72 wrote: is forever unlinked
I don't know what that's supposed to mean.
thenutz72 wrote: way to do something more like
No, that's silly.
|
|
|
|
|
This really doesn't make any sense to me.
What does this even mean?
thenutz72 wrote: m_Myclass = ref objIn;
|
|
|
|
|
thenutz72 wrote: It's like you can have reference behaviour through functions that you cannot have WITHIN the function.
Pretty much everything is done by reference:
MyObject foo = new MyObject();
foo is a reference to the object created by the constructor. When it gets used it is automatically de-referenced, see this[^] for the c# boxing and unboxing model. When you pass an object to a method it is passed as a reference by default, you have to tell the method if you want it passed by value.
If you need pointers you have to use unmanagedunsafe code, where pointers are available, but in C# you rarely need it. I've being doing this for 10 years, and the only time I had to use pointers was during some interop work I was doing. Oh and a another time after I'd just graduated using c++ and didn't know how C# really worked, which was a bit embarrasing
Finally, please tag up your code with <pre> , it makes it easier to read. Otherwise you'll get responses of varying degrees of snottiness.
[edit]: When I said unmanaged code, I of course meant unsafe code. Better have a nice nap and a cup of tea, I'm getting old!
|
|
|
|
|
Thanks Kieth,
But in my code examples you'll see the ref keyword does act like a pointer to an object. Where as the assignment operator just assigns a reference. In the former, there are two variables with the same address. The latter, two variables that only point to the same reference.
Use of the new keyword in each scenario will confirm the difference.
I just find it odd that a function parameter can make use of pointers to objects but there's no way to duplicate that behaviour inside of a function. I was able to use unsafe code and pointers to primitive types to share addresses across multple variables. But was unable to do the same with a class/object instance.
|
|
|
|
|
You still haven't explained your question clearly.
|
|
|
|
|
First, in your code, the ref keyword is redundant, the reference pointer is passed round on objects by default, not the value itself.
Second, I'm still really not clear on your question.
private MyClass
public void MyFunction(MyClass objIn)
{
m_MyClass = objIn;
}
public void SomeOtherFunction()
{
m_MyClass = new MyClass()
}
public void Main()
{
MyFunction(new MyClass());
SomeOtherFunction();
}
Which language are you used to using and what exactly are you trying to achieve? If you need pointers you are probably going about things the wrong way in C#.
|
|
|
|
|
Unsafe code?
unsafe
{
int i = 1;
Console.WriteLine((long)&i);
}
Explained on MSDN[^]
I are Troll
|
|
|
|
|
I am not sure if I understand what you want to accomplish. I guess you could try the out keyword instead of the ref keyword.
|
|
|
|
|
How can I encrypt the entire App.config instead of encrypting just the aaSetting or ConnectionStrings only?
|
|
|
|