|
hi
i want to start an application with hidden window, but how to do ?
|
|
|
|
|
|
I have a c library function that returns a structure. How can i get that structure correctly in c#?
I made an exact copy of the structure in c#, added the attribute [StructLayout(LayoutKind.Sequential)]. What do i then do?
Do I have an IntPtr return type in my dll import function (so i can marshall it) or do I just give the dll import function the structure as return type?
like this
<br />
dllimport...<br />
internal static extern mystruct Function();
or
<br />
dllimport...<br />
internal static extern IntPtr Function(); and then marshall it?
|
|
|
|
|
I think it depends on whether the C function is returning the structure by value or is returning a pointer to a structure. Can you post the C function prototype?
|
|
|
|
|
FSLAPI FSL_EAX_LISTENER_PROPERTIES FSLAPIENTRY fslCreateListenerEnvironment(const char* strData, unsigned int size);
FSL_EAX_LISTENER_PROPERTIES is the structure.
|
|
|
|
|
Ok, well it looks like the structure it returned by value. However, to be on the safe side, if you can find the structure's declaration in its header file, that will tell you for sure. "FSL_EAX_LISTENER_PROPERTIES" looks like a typedef. Sometimes C programmers will typedef a structure pointer. That can disguise whether it is a structure or a pointer to a structure. If you can find its declaration in the header file and post it here, we should be able to nail down for sure whether the function is returning a structure by value or a pointer to a structure.
|
|
|
|
|
<br />
struct FSL_EAX_LISTENER_PROPERTIES<br />
{<br />
long lRoom; <br />
long lRoomHF; <br />
float flRoomRolloffFactor; <br />
float flDecayTime; <br />
float flDecayHFRatio; <br />
long lReflections; <br />
float flReflectionsDelay; <br />
long lReverb; <br />
float flReverbDelay; <br />
unsigned long dwEnvironment; <br />
float flEnvironmentSize; <br />
float flEnvironmentDiffusion; <br />
float flAirAbsorptionHF; <br />
unsigned long dwFlags; <br />
};<br />
Thats the structure which was in the header file.
|
|
|
|
|
Ok, no typedefs to pointers there. Here's what I'd use:
[ DllImport( "Kernel32.dll", CharSet=CharSet.Auto )]
public static extern MyStruct fslCreateListenerEnvironment(StringBuilder stringData, UInt32 size);
Where "MyStruct" is the interopted version of FSL_EAX_LISTENER_PROPERTIES.
Unfortunately, I've not been able to find an example on MSDN for marshalling a function that returns a structure by value. So I can't 100% guarantee that this is the correct approach, but I'm relatively certain.
|
|
|
|
|
|
Hi,
I have to open the outlook application.
olApp = new Outlook.ApplicationClass();
But if the outlook is already running, what should I do?
I have the following code to find out if the outlook applicatin is already running. Once I got the processes of current Outlook, how should I assign to olApp??
bool found=false;
Process [] processes = Process.GetProcessesByName("OUTLOOK");
if (processes.Length >= 1)
{
found=true;
}
Thanks.
|
|
|
|
|
I need a variable whose value is known in all program code.
No it's not a constant, it's a variable whose value changes, but i need to access to its value in other program parts.
If i create a class with a property, everytime i change module i need to create a class reference again, and the property is reset to its default value, i need to keep its value all along the program life, this is simple in all other programing languages, but in C# i didn't manage to do this.
How do i do this, and where to do this?
Thank you,
Joaquim
|
|
|
|
|
have you tried creating a public sealed static class with a public static property to get and set the value for that variable. if the class is sealed and static then you don't have to create a reference, all you need is classname.propertyname ....
-----
|
|
|
|
|
Thank you SABhatti, it worked.
But wowww... alone i wouldn't go there.
I did not see any reference to 'public sealed static classes' (uufff..., i'm tired) anywhere in the documentation.
In Visual FoxPro i would do: 'addproperty(_application,PropertyName)', anywhere in the code, and voilá i would have a property that i could access at any part of the code simply by writing:
_application.Propertyname = "value"
or
this.text1.value = _application.Propertyname
Thank you,
Joaquim
|
|
|
|
|
Global variables are generally an indication of poor design. C# therefore does not support them. You can however simiulate them through other means such as the one you have now discovered.
|
|
|
|
|
No Angus, Global variables, or in this case properties, are a means to an end, bad use of global variables are indication of poor design.
And as we now see: C# support them
Joaquim
|
|
|
|
|
joaquimc wrote: Global variables, or in this case properties, are a means to an end, bad use of global variables are indication of poor design.
I didn't say all uses were bad. I said "generally" they were bad. Every time I have the urge to use a global variable I sit and think if it is really really necessary first. Most of the time I come up with a better solution that doesn't involve global variables. These days I rarely think of global variables at all.
Next, properties do not have values. In C# properties are methods dressed up in syntactic sugar. Any value they appear to have is a result of the value that is returned from the underlying method.
joaquimc wrote: And as we now see: C# support them
It doesn't. It is just sugar dressing. It just appears to support them in a contrived way.
|
|
|
|
|
You can't really say that global variables or result of bad design, instead using them badly is bad. But in some cases you definitely need them depending on the requirement..
-----
|
|
|
|
|
Sure you can. Wether or not it's valid to say that is up for debate.
But seriously, I've never seen a situation that warranted globals. Point is there are better ways to handle situations where you want to use them.
|
|
|
|
|
SABhatti wrote: You can't really say that global variables or [are]result of bad design
Yes. I can say that. 99.99% of the time global variables are the result of bad design.
In any situation that I've used them, I've come back to the code sometime later and think why I made that poor descision. Often, rereading the code I'll come up with a better solution.
SABhatti wrote: But in some cases you definitely need them depending on the requirement..
Such as?
|
|
|
|
|
Example: you need a path for a file you'll need throghout the code.
And there are other examples.
Many other examples...
Joaquim
|
|
|
|
|
|
That is a good candidate for something that should be in the app.config file. I have a configuration class in my applications that convert and cache the values from the config file so they are available throughout. In fact, I often have several configuration handling classes because the application has many subsystems that need handling separately.
|
|
|
|
|
And how do you know where is the config file?
(I also use config files, the reason to start this discussion is my config file, i need to know where it is)
Joaquim
-- modified at 19:05 Friday 6th April, 2007
|
|
|
|
|
joaquimc wrote: And how do you know where is the config file?
It is in the same directory as the executable. It will have the same name as the EXE with a .config extension added. You can override that, but that is the default for .NET applications. Or are you not using the builtin configuration classes for some reason?
If you are not using the inbuilt method then how would you be intending to populate the initial value of your global variable?
|
|
|
|
|
The app.config file defaults to being in the same folder as the .EXE. If you didn't want to use the inbuilt configuration handler classes, it's a trivial matter to get the app's, or any assembly for that matter, path that it was loaded from. For example, Application.StartupPath returns the path to the folder that the .EXE was launched from. Couple that with Path.Combine and you can build a fully qualified path to any file or folder in your application.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|