|
fkocak wrote:
what is your opinion about this case ?
To be honest, I don't know
I'm programming C# for the second day right now and I'm not more far than with a simple "Hello World"-program. I just thought API-usage is same easy as in C++, but I've got disappointed in this case
modified 12-Sep-18 21:01pm.
|
|
|
|
|
no, not like that. It is hard but not impossible
Nothing is impossible, just may be a bit difficult that is all
What i am trying to tell is we have to decide what kinf of method we have to use for api declarations in C#. for example, we can type a function declaration and use it in our programs. but one day we may need to call that function with different parameters and then we have to add a new declaration of that function for our new need. what i mean is that, if we will build a library for Win32 Api, then people must find for what they are looking int this library. This only makes an increase in the count of the functions in the library. but most important part to build such kind of library is we need to test each ported function in a test program. In many cases, to test even a function you need to write so many lines of code to make sure that a ported function works properly. for example, in the one of my projects i declared 8 DeviceIOControl functions for different parameters.
And much times, to write a program is easier than to make changements or addition in a ready program. so, if we will build a library we have to decide a common strategy for all the functions to be ported.
Maybe i am wrong or not so much positive. do you ?
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
fkocak wrote:
for example, we can type a function declaration and use it in our programs. but one day we may need to call that function with different parameters and then we have to add a new declaration of that function for our new need.
and:
fkocak wrote:
for example, in the one of my projects i declared 8 DeviceIOControl functions for different parameters.
I don't get the point, I think Win32 API functions have no overloaded functions, so that it's enough to convert just function per function. Once a function is ported you can go to the next one and port it as well. All there is to consider is to port all parameter names(values) as well, e.g. for all WM_ messages.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
no, that is not what i point to,
Yes, there is one declaration in Win32 Api. But i mean C#. for example, suppose that there is win32 Api which has a pointer parameter accepting some data. And then you have a string variable and a struct variable and a byte value having the data of that function accepts. Can you write a single function in C# without doing any extra converting codes to execute that function ? You have 2 ways to do
1- ) You will write a single function. And will type that pointer paremeter as a known type , say it is IntPTr. And then - to pass a string, a struct and a byte value - you will have to make some converting codes to obtain those variables in a IntPtr.
2 - ) Or simply you will write 3 functions with those types instead of IntPtr.
As you know, C# supports overloading
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
I would prefer method 1), I can tell you why:
I currently read a C#-book and I am already finished with the "conversion"-chapter, and it seems to me that doing conversions in C# is a fairly easy thing, since C# provides functions like ToString, ToByte and so on. So the developer who uses the Win32 API library has to concentrate only on one function and can do the conversion however he likes
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
After reading jdunlap's answer, i can say that we can stop thinking about which way we should use
And, in my opinion, what the difficult thing is not to write 2 or more overloads for a function but to write parameter conversion codes for each type that a user wants to pass to a function.
Anyway, i believe that to start from somewhere is better than not to start ever
Let's start ?
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Actually, there's not a whole lot of them, and with some of them, you can get away with just declaring that parameter as object, and setting the MarshallType attribute to MarshallTypes.AsAny. (In fact, you might try that with SendMessage - you'll have 3 overloads: ref object lParam, object lParam, and out object lParam. The lParam will have the MarshallType set to AsAny for each of them.)
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
hi,
your solution seems to be more logical. I have never tried this definition. I think i should.
Do you still want to finish Win32Api project if you have already not finished ?
I currently have 3 projects waiting to be finished. And A new one won't hurt though
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
fkocak wrote:
Do you still want to finish Win32Api project if you have already not finished ?
Yes. I have a bunch of declares written, but it hardly makes a dent in the Windows API. I'm always making new ones though. I'll put together a class for user, for gdi, for kernel, etc, and put my API's in it. You send me any API's you write, and every time we update, I'll post the new version to my hosting space.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I have some declarations but they are everywhere in my projects. I have to collect them in one place. And to prevent to write the same API declarations, please tell me which catagories you have already finished and which catagories i should deal with
cheers,
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Hi,
I extracted all the constants, structures and api declerations from Apiviewer. And then writing a converter program i converted all of them into C#. But all ported functions still need to be revised because they were not converted manually. And i am still trying to make some additions to better use of the newly created classes. By the way, all ported functions were seperated acording the libraries they belong to. and there are 151 classes now. Function classes contain almost 4800 functions, constant class include almost 78000 contants and structure class.. ? i don't know lol.
Would you like me to send it to you when totally finished or you want to get it now or never ?
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
However you want to do it. I now have a GotDotNet workspace for this project[^].
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
PS: Be warned, the GotDotNet Workspaces site is experiencing difficulties right now.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
i will send you structures and functions. Constants file is about 1.6 mb unzipped. I send it to you later.
please check your e-mail box
cheers,
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Greg S. wrote:
I heard that programs written in C# can be compiled on any OS that supports the .NET-Framework, such like Linux. Say I write a C#-program with a GUI (a simple form) that does not take advantage of any specific OS-APIs, will my application work then with a GUI on all operating systems it has been compiled on?
Most of System.Windows.Forms works under Linux, but not all. But yes, in many cases, you will be able to do cross-platform stuff if you don't use OS-specific API's. However, in many cases, there just isn't an implementation in the BCL for something you need to do (like play a sound for instance), and you have to either use the Windows API or forget it. But, you can make generic wrapper classes for Windows, Linux, etc, so that your code can use the generic wrapper class instead of the API directly.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I know this is probably a trivial question, but would you change the volume level of the system? I haven't found any infomration on the net about it. If anyone can give me a hand I would appreciate it. I have tried using the BasicAudio filter from the Interop.QuartzLib but when I change the audio object.Volume and set it to an integer it crashes. Thanks in advance.
Ripsi
|
|
|
|
|
Dear friends,
I am new to ADO.NET. I am able to use DataReader to display data. I failed to insert/update/delete the records. Does anyone know a good and working source for this topic?
Thanks a million $
Khang
PS: I tried out the following example but did not work!
Code Project/.NET - Simple ADO.NET Database Read, Insert, Update and Delete using C#. by John McTainsh
|
|
|
|
|
To read,insert update data in an access db and in general with the oledbprovider there are 2 ways.
The easy way is to use the wizard in the visual studio when yu create a OledbDataadapter from the data tab in the toolbar, which creates a oledbdataadapter which can read data in a dataset, and after that if you change any data in the dataset, using the update method of the oledbdataadapter object you insert any new item and update any changes made in the dataset or in a specified table.This way is fast and doesn't need any special knowledge but allows only easy updates.
The second way is either to create a connection to the db and after that create some oledbCommand objects with sql syntax like
"INSERT INTO [tablename]([field1].[field2]...) VALUES([value1],[value2]...)"
to insert a new row,
"UPDATE [tablename] SET [field1]=[value1] WHERE [criteria]"
to update an existing row,
"DELETE FROM [tablename] WHERE [criteria]
and execute them directly, or create the oledbcommands and creat an oledbadapter object and set the properties updatecommand,insertcommand,deletecommand and selectcommand.This method with the oledbadapter requires the knowledge of using parameters with the commands.
|
|
|
|
|
Thank you so much for the tips, Dimitris!
Khang
|
|
|
|
|
i need alittle help.............how do i use this: System.Web.UI.HtmlControls.HtmlInputFile
in a windows application
Thank in advance
Da Intern
|
|
|
|
|
you cannot use this control in a windows app, you should create your own using a textbox,a button and a System.Windows.Forms.Openfiledialogcontrol. It's easy to do it. Let's say tha name of the textbox is filetxt and of the button is mainbutton and of th openfiledialog is ofdcontrol.
write this code on the click event of the mainbutton [c#]
if (ofdcontrol.showdialog()==System.windows.forms.dialogresult.ok) filetxt.text=ofdcontrol.filename;
that's it
|
|
|
|
|
Thanks for the help but i'm alittle lost. I want to recreate this this section of code for a windows application.
<code>protected System.Web.UI.HtmlControls.HtmlInputFile Upload;
private void Button1_Click(object sender, System.EventArgs e)
{
//It verifies if the archive exists
if (Upload.PostedFile != null)
{
//To create a PostedFile
HttpPostedFile File = Upload.PostedFile;
//Create byte Array with file len
byte[] Data = new Byte[File.ContentLength];
//force the control to load data in array
File.InputStream.Read(Data,0,File.ContentLength);
int i = 0;
//Dysplay array data in textbox
for (i=0;i<Data.Length;i++)
{
TextBox1.Text += Data[i].ToString();
}
//Create procedure parameter
object[] obj = new object[1];
obj[0] = Data;
//Execute the procedure with Microsoft.ApplicationBlocks.Data
//Simple procedure
/*CREATE PROCEDURE sp_img(@img image) AS
insert into tb_img values(@img)*/
//record data
SqlHelper.ExecuteNonQuery(connectionString,"sp_img",obj);
}
}</code>
Da Intern
|
|
|
|
|
Hi all
I wrote a Windows service and I installed the same on two machines. I gotto start the first instance of the windows service, if and onlt if the second one isnt running. I tried implementing this using the ServiceProcess class. At the time of executing the ServiceController.Stop line, am getting an exception saying that "Unable to open the service at this machine".
Is there anyway to do this?
Thanks in advance
Karthik
|
|
|
|
|
The issue is not with the installation. Its with the way I wanna access the same instance of the service running in different machine. Using System.ServiceController, I could able to access that service( via Windows forms application )by providing its machine name, service name, etc.
But the same code is throwing the exception while used in the On_Start method in Windows service code!!
|
|
|
|
|
My OnStart method has the below check point,
if (myServiceController.CanStop==true)
{
Console.WriteLine(myServiceController.CanStop);
//IPAddress[] iPAddresss = Dns.GetHostByName(Dns.GetHostName()).AddressList;
IPHostEntry myHost = new IPHostEntry();
Console.WriteLine(Dns.GetHostName());
myServiceController.Stop();
}
else
{
Console.WriteLine("Cant Stop");
}
Thanks
Karthik
|
|
|
|