|
C# doesn't use header files. You'll have to rewrite the C++ constants, structures, function headers, whatever your trying to use in the header file, into C# code.
RageInTheMachine9532
|
|
|
|
|
I want to use a variable (or constant) in following class property:
[EventTrackingEnabled(true),ObjectPooling(true,1,50)]
public class Aktualizacje : ServicedComponent
{...
instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv
Hi,
AW
|
|
|
|
|
You can declare constants and use those in your attributes, but not variables. Since attributes are metadata, the values must be defined at compile-time, not at runtime.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Just overload the constructor, very handy with attributes. Remember attributes are readonly because they are stored in metadata, and hence, can be changed at runtime.
|
|
|
|
|
|
Hi friends
I have a problem. I have a login form in visual C# in which user must enter username amd password and then click login. If username or password is blank then one messegebox display that "Please enter username and password". After that i want to exit that sub. In Visual besic .Net there is command "EXIT SUB". In visual C# there is a static method call Application.exit but it is for close the whole application but i want only to exit the event and application should not be close.
Please reply me as early as possible
Thank you.
(Hemant Uttam Mane) 
|
|
|
|
|
Application.Exit() static method. See help
Hi,
AW
|
|
|
|
|
He said he didn't want to call that and exit the whole application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
normally you can exit a sub (in C# it's called method) with return....like this:
public void Login()
{
return;
}
|
|
|
|
|
Hi,
I have a structure declared with bit fields in one of the C++ dll I am calling in my c# application. How can I change it to C# type struct?
typedef unsigned int UINT32;
typedef struct DEV_TYPE
{
UINT32 ReadCdR :1;
UINT32 ReadCdRw :1;
UINT32 ReadDvdRom :1;
UINT32 ReadDvdRam :1;
UINT32 ReadDvdMinusR :1;
UINT32 ReadDvdMinusRw :1;
UINT32 ReadDvdPlusR :1;
UINT32 ReadDvdPlusRw :1;
UINT32 WriteCdR :1;
UINT32 WriteCdRw :1;
UINT32 Reserved0 :1;
UINT32 WriteDvdRam :1;
UINT32 WriteDvdMinusR :1;
UINT32 WriteDvdMinusRw:1;
UINT32 WriteDvdPlusR :1;
UINT32 WriteDvdPlusRw :1;
UINT32 TapeDrive :1;
UINT32 Reserved :15;
} DEV_TYPE;
I have read in MSDN that C# does not support bit fields. Is there any method to implement this structure in C#? Pls help..
Thanks
Vini
|
|
|
|
|
Use BitArray(sealed) or BitVector32 or try to create new class using uint and next define set/get properties:
private uint a=0;
public uint A
{
set { A=value; }
get { return a; }
}
public uint A0
{
set { a &= 0xFEU; if(value>0) a+=0x1U; }
get { return a & 0x01U; }
}
...
Hi,
AW
|
|
|
|
|
I got it with BitVector32 BitVector32.CreateSection Method and get/set methods.
Thanks
Vini
|
|
|
|
|
Hi Vini,
I am also having the same problem using bit fields in C#. Is it possible for you to post ur sample code?
Thanks,
- Prerna
|
|
|
|
|
Your C# code could just pass/receive a uint from the .dll. Just use the bitwise operators in C# to set up or read the various bits.
You'd have to define your bits differently and wouldn't really use a 'bit field' but you'd get the same effect of storing several bools in a single 32 bit variable.
i.e.
C++:
const UINT32 ReadCdR = 0x00000001;
const UINT32 ReadCdRw = 0x00000002;
const UINT32 ReadDvdRom = 0x00000004;
...
const UINT32 TapeDrive = 0x0000FFFF;
bool DoSomething(UINT32 devType)
{
if (devType & ReadCdR)
...
}
C#:
private static uint ReadCdR = 0x00000001;
private static uint ReadCdRw = 0x00000002;
private static uint ReadDvdRom = 0x00000004;
...
private static uint TapeDrive = 0x0000FFFF;
public static CallSomethingInDll()
{
uint val = ReadCdR | ReadCdRw | TapeDrive;
bool ret = CPPWrapperOrManagedClass.DoSomething(val);
}
|
|
|
|
|
C# has constants too
Hi,
AW
|
|
|
|
|
O lord, another programmer trying to be clever without knowing how to use bit masks (not you). This is what it should look like both sides...
[Flags]
enum DEV_TYPE
{
ReadCdR =1 << 0,
ReadCdRw =1 << 1,
ReadDvdRom =1 << 2,
ReadDvdRam =1 << 3,
ReadDvdMinusR =1 << 4,
ReadDvdMinusRw =1 << 5,
ReadDvdPlusR =1 << 6,
ReadDvdPlusRw =1 << 7,
WriteCdR =1 << 8,
WriteCdRw =1 << 9,
WriteDvdRam =1 << 11,
WriteDvdMinusR =1 << 12,
WriteDvdMinusRw=1 << 13,
WriteDvdPlusR =1 << 14,
WriteDvdPlusRw =1 << 15,
TapeDrive =1 << 16,
}
|
|
|
|
|
Has anyone experimented with using structs or classes in C# to carry data rather than strongly typed Datasets in a Webservice environment?
VS.NET makes it as difficult as possible to pass classes and strongly-typed ArrayLists of classes in and out of Webservices and as easy as possible to use Datasets with Webservices and with MSSQL.
Nevertheless, profiling a recent project that used strongly typed Datasets showed that there is a massive run-time cost to using them (lot of meta data around and many Events being fired) which led us on to thinking about using good old structs.
We have successfully passed 'property only' classes in and out of Webservices (including classes that include other classes and arrays and ArrayLists of classes) and bound strongly typed ArrayLists to DataGrids and we can use a property by property approach together with stored procedures to get data in and out of an MSSQL database. The code we have produced could be 'templated' (generics will be wonderful) meaning that, in theory, we could stop using strongly-typed datasets.
On the other hand - who wants to reinvent the wheel if MS have done all the work for us in creating Datasets?
Has anyone else agonised over this decision and, if so, what conclusion did you come to?
Thanks
Bernard Yardley
|
|
|
|
|
It's not VS.NET that's causing the problem, it's your implementation of how it defines the WSDL for the Web Service. Even generic DataSet will produce a generic declaration in WSDL. And there is not such thing as a typed ArrayList - it works only with object s, unless you've extended it and declared typed parameters.
Structs, classes, DataSet s, whatever work well so long as they can be serialized correctly / the way you want. By default, Web Services use XML Serialization attributes or simply uses the public properties (not fields, and this is documented) and their names. See XML and SOAP Serialization[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry - my reference to a strongly-typed ArrayList was 'lazy' English. What we actually did was create a class named MyClassList that implemented IList (to give bindability to a DataGrid) and had a private ArrayList member. It then implemented all the Methods of IList by passing them on to the ArrayList except that this[]{get()} and Add() were both typed rather than returning/accepting object s.
Our problem with WebServices was that the proxy class that VS.NET builds contained its own declarations of the data classes, so you ended up with MyNamespace.MyClass and localhost.Webservice.MyClass so Method signatures didn't match and the code wouldn't compile. The solution seemed to be simply to go into the file that VS.NET built and delete the lines that declared MyClass - then everything compiled and ran fine. Are you saying that a tweak to the way VS.NET calls WSDL would solve this problem?
My real interest, though, is whether anybody else is attempting this or just sticking to using strongly-typed Datasets to do everything?
Thanks
Bernard
|
|
|
|
|
No, just declare your classes and structs properly, perhaps attributing them with the XML Serialization attributes in System.Xml.Serialization to provide greater control.
Also, why is MyClass (assuming it's the same class) in both assemblies? Your Web Service should be declared in a different assembly and doesn't need to access it's own WSDL - it's the one generating it (rather, the ASP.NET facilities are, but for your classes).
I've used many classes in Web Services and we even use them in .NET Remoting (but that's subject to different technology, though similar in concept). There's also examples included right in the .NET Framework SDK itself, as well as examples throughout the documentation for Web Service-related classes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To cut this down to the bone, I've got three projects, MyClasses , MyClient and MyWebService and let's assume that the namespaces are the same as the project names. MyClasses contains the definition for MyClass . MyClient and MyWebService both reference the MyClasses namespace. Now let's say that MyWebService has a webservice in it, MyWS.asmx that in turn has a method whose parameter is of type MyClass or, to be precise, MyClasses.MyClass .
When I add MyWS as a web reference to MyClient, VS invokes WSDL to build a proxy for MyWS for MyClient to use which includes a new definition for MyClass. So we now have a situation where MyClient is aware of MyClasses.MyClass and is calling a Method with that type as parameter but the proxy is expecting an object of type localhost.MyWebService.MyClass (or whatever). Hence the code will not compile.
The example in MSDN seems to get round this issue by only declaring the class on the proxy file but that seems to me to be a backwards way of going about things - but maybe I've misunderstood?
Anyway, is this any clearer?
The WSDL documentation seems to suggest that the correct approach is to generate the proxy class and then modify the code by hand so I still end up back at my core question of whether there is a better or worse way of passing data between the layers from a front end via a web service, then to COM+ and finally to a SQL database or is it just as good to use our own classes as to use strongly-typed Datasets?
Thanks
Bernard
|
|
|
|
|
It was clear to begin with, but you're the intent of WSDL. The WSDL file for your web service is used to generate the client proxy, including all types necessary to makes calls on your web service. This is what WSDL is for, and what helps makes web services platform- and implementation-independent. You can discover information about a web service using the ubiquitous XML format, even at runtime.
What you're trying to do is more of a .NET Remoting tactic. You don't need to have an assembly that defines your types, since the client proxy that is generated will contain them - that again is what WSDL is partly for (to describe the types used, as well as all the methods, etc.). If you do want to share the types (perhaps they have some handy methods), then simply go into the generated class file (just show hidden files in your project) and change the type to your class from the MyClasses assembly.
Again, going back to the original question of classes vs. structs vs. DataSet s - you can use anything. You can pass the intrinics (int, long, string, char, etc.) and anything else you like, even arrays like a byte[] array (commonly used for images, though DIME is much faster).
What you use is up to you and your implementation, but you can use anything. Take a look at http://www.xmethods.net[^] for a huge list of web services, most (all?) of which don't use DataSet s and just return whatever types they want, which are defined in the web service's WSDL.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think I've got it! What you're saying is that I only reference MyClasses from MyWebService and not from MyClient; MyClient then uses the classes in the file that WSDL builds.
The classes we're passing specifically don't have methods, they're just a means for carrying data so that issue doesn't arise.
I'll have an experiment with this and see where it goes.
Thanks for your help
Bernard
|
|
|
|
|
hi
i have a map of picture in rgb . i want to show it in a picture box but i can,t find any method to convert byte[](i mean map) to image.
can enybody help me.
Regards Amir jalaly
|
|
|
|
|