|
That is all!
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
|
i'm new in programing opengl so.....
I'm heaving troubles implementing the fog function, is it possible for anyone to send me implementation for this function?
M Shedid
|
|
|
|
|
|
thank you , but i want to use fog in a still image, not in animation, is it possible, as if i'm making a scene, so how may i do it?
|
|
|
|
|
IS there a way to know if the client is disconnected.
My server basically receives data from the client. It uses syncronous connection with a winodw timer (Thus avoiding completly teh multitreading issue.)
|
|
|
|
|
This is a very ambiguous question. What client/server technology are you using? A simple TCP socket? .NET Remoting? Web Services? WebRequest s? More information would be helpful.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using simple TCP sockets.
|
|
|
|
|
Then it depends greatly on your implementation. Some protocols - like DICT - will require that a client - if possible - send a QUIT message (or equivalent) for proper implementation. This tells the server that your client is disconnecting. Otherwise, when your server sends data you should catch any exceptions - which you should be doing anyway - and handle them appropriately. If you get a SocketException , for instance, check the SocketException.ErrorCode for WSAECONNRESET (10054) or WSAENOTCONN (10057). See the Windows Sockets V2 Error Codes[^] on MSDN for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Open a cmd prompt at your server and type:
netstat -a
Netstat then displays all connections and listening ports.
Check the Microsoft Windows 2000 Server Documentation on Command-line Utilities or type netstat /? for help.
Regards,
-Ron
Sincerely,
-Ron
|
|
|
|
|
I have a component that supports transactions. One of the method needs to know if it is within a transaction or not. Is there a way to know?
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
How about ContextUtil.IsInTransaction ? There's other related methods for getting the transaction and its ID. Just see the .NET Framework SDK documentation for the System.EnterpriseServices namespace.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Tx for the answer, exactly what I was looking for.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hello,
I have a third party DLL that contains a create function, it creates an object in memory and returns a handle to it. When I am finished with it I can call a Destroy function with the handle to get rid of the object. While I am using the object each function the DLL has takes the handle to the object.
My question is: How do I write the DllImport stuff to get this handle properly?
I've tried:
[DllImport("tp.dll")]
internal static extern unsafe void* OpenFilter();
[DllImport("tp.dll")]
internal static extern unsafe void CloseFilter(void* handle);
[DllImport("tp.dll")]
internal static extern unsafe int IsOpen(void* handle);
and the same again with the void* replaced by IntPtr.
What am I doing wrong? If I write a test application in C I can use the DLL fine, but if I try the same in C# it doesn't work. Is there a problem with the way the third party DLL allocated its memory?
The third party DLL exposes C style functions and the same API as a C++ class (compatible with Visual C++ 6.0)
Any help would be much appreciated.
Cheers,
Andy.
|
|
|
|
|
Andy MacAngus wrote:
[DllImport("tp.dll")]internal static extern unsafe void* OpenFilter();[DllImport("tp.dll")]internal static extern unsafe void CloseFilter(void* handle);[DllImport("tp.dll")]internal static extern unsafe int IsOpen(void* handle);
Just a guess, but try:
[DllImport("tp.dll")]
public static extern IntPtr OpenFilter();
[DllImport("tp.dll")]
public static extern void CloseFilter(IntPtr handle);
[DllImport("tp.dll")]
public static extern int IsOpen(IntPtr handle);
- Nick Parker My Blog
|
|
|
|
|
You never mentioned what the problem is. Since you're using C-style declarations, that clears-up one problem. Is this native DLL in a resolvable directory (i.e., current working directory or something in the %PATH%)? Are any exceptions thrown, and - if so - what exception (i.e., Type and text)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for answering.
Yes, this is a native DLL - I believe it was written with Visual C/C++ 6.0 (the C++ part of it only works when linked with VC++6)
The DLL is in the same directory as the C# exe.
No exceptions are thrown. I think that the pointer that I am receiving back is not right but I don't know how to tell or not. If a native DLL allocates memory when being used in a managed application is there anything special I need to do? I've written a test application in C as well as the C# version and the test works in C - the code is virtually identical.
The symptom of the error is that when running in C# the IsOpen() function always returns false.
|
|
|
|
|
Andy MacAngus wrote:
If a native DLL allocates memory when being used in a managed application is there anything special I need to do?
It depends. Is the caller expected to free the memory? If so, you should use GlobalAlloc or CoTaskMem , which you can free with the Marshal class methods.
What is this a pointer to? If it's a pointer to a struct, for instance, you need to define that struct in managed code and you can use Marshal.PtrToStructure . Keep in mind your managed-unmanaged marshaling, too, which you can control with MarshalAsAttribute and knowledge of bit-lengths (like an int in unmanaged code should use UnmanagedType.SysInt since its bit-length is system-dependent, and a LONG and INT in unmanaged code are both an Int32 in managed code.
Note, from what I can tell, you don't need any unsafe code here. IntPtr will usually do what you need it to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
The caller is not expected to do anything to allocate or deallocate memory. The OpenFilter() and CloseFilter() functions do that. They return a HANDLE (which is just a C-macro definition for void*) so it is a pointer to something I don't know much about it is all accessed through the API that the DLL exposes.
I tried using the IntPrr but I just get the same results. What is most fustrating is that I can see it working in C (all I am doing in my test is an open, test for is open then close)
Cheers,
Andy
|
|
|
|
|
Andy MacAngus wrote:
They return a HANDLE (which is just a C-macro definition for void*)
Thanks, I know! I started programming on C many, many years ago. Still use it sometimes.
What you're doing isn't at all different from what MANY classes in the .NET base class library, do. Take controls in Windows Forms, for example - they all use window handles (HWND s), as well as many other types of handles (all typedefs of the same thing, of course).
You mentioned that you're checking the return of IsOpen against a boolean expression. Are you comparing against true or false ? Or are you equating the return against 0, 1, some negative number, etc? In the former case, you should declare your method return value as a bool , so long as the concept of a boolean in your unmanaged code uses 0 for false and anything else for true (like the BOOL typedef). You'd probably get compiler errors otherwise, but I honestly can't see the problem.
You're right to use an IntPtr for void* . Despite your return value, do you get a valid memory address? If you share these two projects in a simple solution (you'll have to upgrade the old VC++ 6 project, of course), you could actually debug projects and see what is happening in both managed and unmanaged code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
so long as the concept of a boolean in your unmanaged code uses 0 for false and anything else for true
Yes, that's what I'm doing:
if (IsOpen(_handle) == 0)
{
Console.WriteLine("Not Open");
return;
}
else
{
Console.WriteLine("Open");
}
Heath Stewart wrote:
you could actually debug projects and see what is happening in both managed and unmanaged code.
That's what I'm going to do. Thanks for your help. This is probably a little bit more complex than I had hoped.
|
|
|
|
|
It's not complex, just odd. Like I said, the base class library uses handles for much of the functionality, from drawing to controls to image lists to file streams and more. I use this type of approach a lot myself. Anything dealing with ActiveX controls uses a lot of handles. Overriding functionality of an existing control almost always requires working with handles and passing them to unmanaged functions. In these cases, you merely use IntPtr for handles.
The only other thing that I can think of is that you could try using ref IntPtr p as your parameter (or replace ref with out ). This usually isn't required, though. So your calls would look like:
IntPtr ptr;
OpenFilter(out ptr);
if (IsOpen(ptr) == 0) CloseFilter(ptr); OpenFilter would have to be declared with ref or out as well. ref requires an instantiated input and is typically used for [in, out] declarations, where out does not require an instance is is typically used for [out] declarations.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i want to get the window coordinates
|
|
|
|
|
Of what? Your form? You can use Form.PointToScreen(this.Bounds) to get a Point in scren coordinates, where this is your Form class. PointToScreen is actually a static method inheritted from Control .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i dont want to get the form coordinates but i have the handle of specific window and i want to get its coordinates i knew the Fn. but i dont know how to use it in C# the Function is bool GetWindowRect(HWnd,LpRect)
i donot know how use the pointer.
|
|
|
|