|
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
|
|
|
|
|
well thank for the help no doubt ill have some more
|
|
|
|
|
I got a DataGrid and I want to set a string for the cell(rowNumber, colNumber) but i do not known how to do it.
Help me please.
Thanks a lots.
Mr Duc Linh Nguyen
|
|
|
|
|
See the DataGrid.CurrentCell property documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I have tried to integrate Microsoft.DirectX.dll into my
project, but when i'm running:
regsvr32 Microsoft.DirectX.dll , I'm getting error message:
"File was loaded dut DllRegisterServer entry point was not found. Registration failed." I thougth if I had regsvr32.exe file then I had DllRegisterServer. Can anyone tell me what is going on and what to do?
Thanks
|
|
|
|
|
I do not understand why did you do this ?
I do not understand what is your prupose?
if you want to use the dll.you can referance it
in any folder.you can put the dll in the folder.
referance it.ok?
it is my addvice.
|
|
|
|
|
regsvr32.exe is a utility used to register COM objects on your computer. A COM object lives in a DLL that exports a couple of pre-defined functions, such as DllRegisterServer.
If you want to install a COM (or ActiveX, which is the same) DLL on your computer, you may use regsvr32.exe to do that.
If you have a simple DLL, however, which does not contain any COM objects, you do not need to run regsvr32.exe; in such a case, you can simply call the functions exported from that DLL, maybe by using the DllImport attribute (if you want to do it with C# or VB.NET).
|
|
|
|
|
Andy is right, but I wanted to add that regsvr32.exe will never work on .NET assemblies. IF you have to register a .NET assembly (only when it contains CCWs, or COM-Callable Wrappers), you must use regasm.exe instead.
Note: you do not need to register the Managed DirectX assemblies. They are written from the ground-up and make little to no use of the DirectX APIs or COM servers and do not expose any CCWs that require the assembly to be registered. Besides, the Managed DirectX installer takes care of everything or simply fails if it can't perform a required action. You do not need to do anything else besides install the Managed DirectX runtime on the target machine that will run your application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How to customize PrintPreviewDialog, such that, addition of a new button, change the functionality of existing button should be possible programatically. Sample code will help a lot.
Moreover, what happens before the document gets displayed in PrintPreviewDialog, i.e. whether entire document gets copied in printer driver spool or only 1 or 2 pages?
please guide
regards
sachin
|
|
|
|
|
In order to custom the PrintPreviewDialog , you have to use reflection to get at the controls you want to reposition. It would most likely be easier (and beneficial) to instead write your own dialog that uses the PrintPreviewControl (which PrintPreviewDialog uses as well) and customize it however you like.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
could you please guide where can I get the internal information of PrintPreviewDialog, such that I can add some controls and override existing methods.
|
|
|
|
|
Use the IL Disassembler (ildasm.exe) from the Platform SDK, or a decent decompiler like .NET Reflector[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I have developed an application in C#, I used RichTextBox control for my word processing part. Now I want to add two more functions that are Print Preview and Print but I had not found any built-in method regarding Print issue with RTB. I am thinking about writing code for the event PrintDocument.PrintPage, hmmm. However, it seems not to be a good idea, I know that I would not have to do that if I deal with the problem using MFC. Though... Buddies suggest me what to do pls.
Thanks a lot.
J. Alpha
|
|
|
|
|
If you're talking about using MFC, then I assume you have some version of the visual studios. There are a couple of methods you can use for printing. The first is by using the PrintDocument, PrintDialog, PrintPreviewDialog, and PrintPreviewControls. If you're used to MFC, then you'll think these controls are wonderful...I thought they were much easier to use than the printing functions that MFC provides. The second method is by using the Crystal Reports. If you've never used it before, it'll probably take you a couple of hours to get the hang of it, but once you do, you'll be able to set up your print/print preview in a matter of minutes from now on. I recommend the second. Good luck!
|
|
|
|
|
|
I'm having a problem with the Convert.ToSingle and the O:C formatting rounding off my floating-point numbers.
When I .ToString a float, it rounds the number. It also rounds it if I use the "C" or "F" format strings (i.e. num.ToString("C"))
How can I accurately display a float/currency value w/o it being rounded off?
Thanks!
-v
****************************
V. Jenks
www.scientifik.com
|
|
|
|
|
Get an instance of the NumberFormatInfo and set the CurrencyDecimalDigits property to something higher than 2 (for example). When you use any of the string formatting methods (like Double.ToString ), pass this instance as the IFormatProvider argument.
See the NumberFormatInfo.CurrencyDecimalDigits property documentation in the .NET Framework SDK for more information and an example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|