|
Hi!
I have a piece of code that maybe helps.
<br />
try<br />
{<br />
System.Net.Dns.GetHostByAddress(serverAddress);<br />
}<br />
catch (System.Net.Sockets.SocketException)<br />
{<br />
}<br />
The exception is thrown, when no computer with the specified address is reachable. The serverAddress can either be a string specifing an IP-address or an object of IPAddress class. See documentation for further information.
Maybe you could build a loop and process this test for every address possible in your local network. This may be not very efficient, but at least it's better than nothing
|
|
|
|
|
thanks for DrGreen (pedrosferreira@hotmail.com) 's suggestion first.
then here is my question:
i get many small bitmap parts from a large bitmap and turn them into stream which can be sent through socket. of course every part has its original coordinary(x,y), so i can restore the original large bitmap correctly .
now ,i need to draw the the recived image parts to a bitmap in memory .
How to write the code ?
please show me the way.
|
|
|
|
|
In this example dest is the destination bitmap and SourceBmp is the source bitmap, I've used x and y loops to simulate putting many smaller (48x48 pixedl) bitmaps into one large (192x192 pixel) bitmap.
Bitmap dest = new Bitmap(48*4, 48*4);
Graphics g = Graphics.FromImage(dest);
for(int x = 0; x<4; x++)
{
for(int y = 0; y<4; y++)
{
g.DrawImage(SourceBmp,x*48,y*48,48,48);
}
}
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event[^].
|
|
|
|
|
I Have a class that inherits from the Frameworks DataTable, and i wish to serialize it.
I added the Serializable attribute to the class but when i deserialized i got an exception that said that i needed a constructor that could create the instance by deserialization. Then i noticed that the private members of my class were not serialized since the DataTable class implements ISerializable, so i need to override the GetObjectData method, but it is somehow defined as private in the DataTable class (According to the Reflector).
If anyone encountered a problem like this and knows the solution i would appreciate it.
I Tried it with the HashTable class and didn't have any problems, this is only with the DataTable class.
|
|
|
|
|
GetObjectData is an exlicit interface implementation. Depending on what you add to your derivative DataTable class, you probably don't need to override this anyway. To define the constructor, create a constructor for your class (any access modifier will work since reflection is used to invoke it) that follows the following pattern/example:
protected MyDataTable(SerializationInfo info, StreamingContext context) {}
You should also look into typed DataSet . These can easily be created in VS.NET (add a new DataSet item to your project from Add-<Add New Item). This is an easy way to create a typed DataSet with typed DataTable s and DataRow s (actually, the columns themselves) that are faster when accessing data by their column name and use the default serialization provided by the DataSet and DataTable to serialize your typed DataSet correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My problem is not with the deserialization, it is with the serialization it self.
My private members are not serialized so thats why i want to use the GetObjectData method, but when i use it i cannot call the base class's method since it is private and there for i can either serialize my members, or my bases members but not both.
I cannot use a DataSet because it will cause too many changes in my code.
I would appreciate any help on this matter.
|
|
|
|
|
You can call it. Like I said, it's an explicit interface implementation, which means you must cast the base to the interface in order to call it like so:
((ISerializable)base).GetDataObject(info, context); (where info and context are your parameters for your implementation of GetDataObject ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The compiler does not permit this call, it said that :
'the keyword base is not allowed in this context'
|
|
|
|
|
So it does. Guess you'll have to refactor your code, then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi every one:
I want to shutdown computer .
but I can not succed in xp.The ExitWindow can not
work .Could you give me some addvices?
|
|
|
|
|
ExitWindows can only log-off the current user if declared correctly. You must P/Invoke ExitWindowsEx in order to specify any shutdown parameters, like the following sample shows:
using System;
using System.Runtime.InteropServices;
public class Test2
{
static void Main()
{
ExitWindowsEx(ConvertFlags(ShutdownFlags.Logoff), 0);
}
[DllImport("user32.dll")]
private static extern bool ExitWindowsEx(
[MarshalAs(UnmanagedType.SysUInt)] IntPtr flags,
[MarshalAs(UnmanagedType.U4)] int reason);
private static IntPtr ConvertFlags(ShutdownFlags flags)
{
return new IntPtr((int)flags);
}
[Flags]
private enum ShutdownFlags
{
Logoff = 0,
Shutdown = 1,
Reboot = 2,
Force = 4,
Poweroff = 8,
ForceIfHung = 16
}
} You'll notice that the first parameter is declared as an IntPtr . This is because UINT is an unsigned int , which is architecture-dependent. On 32-bit operating systems, this is a 32-bit unsigned int. On 64-bit operating systems, this is a 64-bit unsigned integer. It's marshaled as an UnmanagedType.SysUInt for portability.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you.
but we must have purview when we want to shutdown in xp.
we can not use ExitWindowsEx only
|
|
|
|
|
Be specific in your requests, then. You didn't say you wanted a dialog. In that case, P/Invoke RestartDialog or RestartDialogEx from shell32.dll.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you:
I want to say we must get privileges in xp to shut down.
we can not use ExitWindow only.
sdfasd
|
|
|
|
|
You need to P/Invoke AdjustTokenPrivileges using the SE_SHUTDOWN_NAME or something like that, then. It will all be documented in the ExitWindows and ExitWindowsEx function documentation in the Platform SDK in the MSDN Library[^]. You should read it for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you:
Could you give me a example.
I can not change the C++ example to C#.
Thank you very much.
sdfasd
|
|
|
|
|
See http://www.mentalis.org/soft/class.qpx?id=7[^] for an example (did a quick google search on "ExitWindows C#"). There's a lot of code involved, so it's just better to point you at an existing implementation.
Alternatively, you could use WMI to shutdown a computer, which will be much easier but more restrictive since WMI must be installed an the necessary CIMv2 classes must be present.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have an unmanaged C++ DLL which exports certain classes. I want to access these classes from the C# client. I was able to do so by modifying the DLL source to export class creation and destruction functions. Is this the only option for the problem? If I don't have the source code for the DLL, but just the .dll file, how can i access the exported methods from the dll, in C# client?
Also, I have read somewhere about writing a Wrapper class for the DLL, in C#. Is it possible to write the wrapper in C#? Is there any link which will help me in this?
In my c# client , for DllImport, i have given the callingConvention as 'CallingConvention.ThisCall'. One of my exported function has a callBackFunction as argument. I declared a delegate to take care of this. But when executed, the application gives an error of "different calling convention used". If I change the CallingConvention to 'StdCall' or 'cdecl', there is no error, but then the call back function is not called.
[DllImport("ediImgReader - Debug.dll", EntryPoint ="?mapImage@Cedi9660Reader@@QAE_NGP6A_NIPAE_N@Z@Z",CallingConvention=CallingConvention.ThisCall )]
private static extern System.Int32 mapImage(IntPtr inst,System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress);
public delegate System.Int32 ReadSectorDelegate(System.UInt32 SectorToBeRead,System.Byte SetToSectorDataIsLiteral, System.Int32 IsLiteral);
public static System.Int32 ReadSector(System.UInt32 SectorToBeRead,System.Byte SetToSectorDataIsLiteral, System.Int32 IsLiteral)
{
MessageBox.Show("Inside Delegate");
return 1;
}
public static System.Int32 mapImage(System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress)
{
mapImage(Instance.inst,SectorSize,CallbackFunctionAddress);
return 1;
}
Kindly help.
Thanks..
Vini
|
|
|
|
|
I think you can modify the dll if you have the source code.
you can modify the functions which you want to dllimport.
for example you can do "export c mapImage()"
lajiyo
|
|
|
|
|
lajiyo wrote:
I think you can modify the dll if you have the source code.
you can modify the functions which you want to dllimport.
for example you can do "export c mapImage()"
The mapImage() function is a member function of a class and the class is already declared as '__declspec(dllexport)'. But to access the class in my Client, I have created a class derived from 'IDisposable' and declared a member 'private IntPtr inst' to get the access to the exported class. Then the calling convention i need to use is 'ThisCall', isn't? How to remove the exception?
Hope you meant extern "C" or is it 'export c' ?
Vini
|
|
|
|
|
If you want to use C++ classes that are exported from a DLL, you should write a simple wrapper class library in Managed C++. You can then use that wrapper class library from your other .NET projects.
For more details and a simple sample project, look at:
http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/
|
|
|
|
|
when i set the rowheader visible to false it does not work but when i set the column Header to false it does work i need to hide the rowheader in my Windows grid please
|
|
|
|
|
If you don't use DataGridTableStyle s in your DataGrid , then DataGrid.RowHeadersVisible will hide them. If you are using a DataGridTableStyle and it is used for a particular binding (the presense of tables styles doesn't mean they'll be used if the MappingName isn't applicable to the current binding), then the appropriate DataGridTableStyle instance's RowHeadersVisible property will control the visibility of the row headers.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am learning so much from you that worked a treat how do you get time to answer me?
|
|
|
|
|
Good in-depth understanding of the Windows platform and many frameworks an APIs, a good memory, fast typing, and extreme multi-tasking.
Microsoft MVP, Visual C#
My Articles
|
|
|
|