|
5 voted for finding the solution yourself, and then remembering to post it for others to see.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi all,
What can I use within C# to replace the function:
LRESULT SendMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
Many Thanks in advance
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
OK, so I'm using PInvoke - doing the following:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
But I'm receiving the following error:
Error 2 The modifier 'extern' is not valid for this item
Error 3 Expected class, delegate, enum, interface, or struct
Why ???
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
where did you find "HandleRef"? that's why the compiler expected class, delegate, enum, interface, etc I think..
try the code below.. I have no idea how to use it because it only return the message ID which I don't know how to process..
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto)]<br />
private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);<br />
CMIIW
Mail me at erwin@holyknight.us
|
|
|
|
|
Where do I place it. At the moment I placed it here (is this correct?
...
using System.IO;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
namespace WindowsService
{
...
Many thanks for the reply
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi,
Programm3r wrote: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
you have to put these lines inside a class, any class would do (I use LP_user32 for all
user32.dll functions).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yep,
put it inside a class..
search in microsoft documentation for more info about windows messaging, the message type, and other info..
CMIIW
Mail me at erwin@holyknight.us
|
|
|
|
|
Ok, I'm trying this ....
class WindowsService : ServiceBase
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
But I receive this:
Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
using System.Runtime.InteropServices;
All the best,
Martin
|
|
|
|
|
|
Visual Studio is kind enough to include the probable fix in the error message.
MSDN will tell you which namespace DllImport belongs to.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Add this line to your using directives list:
using System.Runtime.InteropServices;
|
|
|
|
|
|
Is it possible to show a MessageBox from a Service developed in C# ?
Many Thanks
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
When you say "Service" do you mean that your C# program is running as a Windows Service? That's my assumption here, and yes it's possible. Whether or not it's advisable is another matter.
Now when I say "possible" I mean that the code will compile and build, and the .exe can be installed as a Windows Service and run. Often times one of the main reasons to develop a solution to run as a Windows Service is so that it can run even when no user is logged in to the computer. Now if that's the case, and the code finds it way down the path to where the MessageBox is .Show()'n, I don't know what will happen. Maybe nothing. Maybe it's displayed and causes the Service to stop executing until the nonexistent user clicks the unseen "OK" button.
Of course you could try it and see what happens. If you do, post your results here so everyone can know, too. Then try to find out if a tree falls in the forest....
BDF
|
|
|
|
|
If you need more information on the code...
//Method for converting a structure or object into a byte[]
public static byte[] RawSerialize(object anything)
{
int rawsize = Marshal.SizeOf(anything);
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
Marshal.StructureToPtr(anything, buffer, false);
byte[] rawdatas = new byte[rawsize];
Marshal.Copy(buffer, rawdatas, 0, rawsize);
Marshal.FreeHGlobal(buffer);
return rawdatas;
}
//Method for converting a raw byte[] from a binaryReader stream to the original structure
public static object RawDeserialize(byte[] rawdatas, Type anytype)
{
int rawsize = Marshal.SizeOf(anytype);
if (rawsize > rawdatas.Length)
return null;
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
Marshal.Copy(rawdatas, 0, buffer, rawsize);
object retobj = (Word)Marshal.PtrToStructure(buffer, anytype);
Marshal.FreeHGlobal(buffer);
return retobj;
}
These are the methods I use to convert to byte[] and back to my struct.
|
|
|
|
|
The structure contains a Hashtable. So it wont be possible to get the size of the structure by Marshal.SizeOf(anything) . Hence you wont be able to convert it to byte array using the above method.
jblouir wrote: public Hashtable htWord;
I am not sure whether it is recommended to use Hashtables/Collection classes in a struct.
*jaans
|
|
|
|
|
Ok,
So if I can figure how to store the same data in say...
a string[]
then ill be fine.
This makes things a bit tricky, I guess ill have to use the hashtable storage outside of the struct, then convert it to a string[] and an int[] and I can pull the values out based on index since I will know that string[1]'s value is int[1].
|
|
|
|
|
This didnt work, I change the hashtable to an int[] and it it threw another error.
TypeLoadException was unhandled
'System.Int32[110]' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has too many dimensions.
|
|
|
|
|
SafeArrayTypeMismatchException was unhandled
'System.Int32[110]' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has too many dimensions.
This occurs when I change the int[500] to int[50] since the last error sounding like there was too much data
|
|
|
|
|
I managed to get it to work finally, I changed the int[] to just a single int and I was able to load the data after I closed the program. This leaves me with a serious problem though, how am I going to load billions of entries without using some sort of organised format.
sigh..
|
|
|
|
|
In RowDataBound event of GridView the DataControlRowState.Edit
will trigger only alternatively.
If we are binding the column with a RadioButtonList,only alternate columns will only get binded.Is there any solution for this.
Regards
Bino
http://www.technix.co.nr
|
|
|
|
|
private void dgContacts_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem item = e.Item;
if (item.ItemType == ListItemType.AlternatingItem ||
item.ItemType == ListItemType.Item)
{
if ((e.Item.ItemIndex % 2) != 0)
{
LinkButton editButton = item.Cells[0].Controls[0] as LinkButton;
if (editButton != null && editButton.CommandName == "Edit")
{
editButton.Visible = false;
}
}
}
}
Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...
|
|
|
|
|
we need to check both conditions (e.Row.Rowstate & DataControlRowSatate)>0
now it will work fine
www.codepal.co.nr
Regards
Bino
http://www.codepal.co.nr
|
|
|
|
|
Hi All,
I am facing problem with the text box whose scrollbars property is enabled to "both".
The Problem is when i retrieve data from a file and show its content in the textbox above specified, I allow the user to type and I have written a small module which when user types "enter" key the format(that is number of tabs or spaces) present in the previous line will be applied to the new line created.
To say it in simple words it is little like the c# programming environment regarding the paragraph indentations it provides to us when we type enter key.
Since I wanted to add text in the textbox in any place where user wish, i am retrieving the text and doing my operations and i put the updated one back to the textbox.
In the above case when data is too large so the scrollbar is active,since i am adding the text in the textbox, the scrollbar is showing the first position though the cursor is blinking in the nextpage.
when I attempt to write it scrollbar moves and it is showing the place where cursor is moving,the moment i type enter it is doing the same i told above. so it is giving a flickering effect. It is annoying a lot.
I had used richtextbox and all those suspendlayout and resumelayout.
Here is my code
\\ code
richTextBox1.SuspendLayout();
\\ gets the current position
iPosition = richTextBox1.SelectionStart;
\\ finds the format of the previous line and stores that in formatpattern string
FormatPattern = FindFormatPattern(richTextBox1.Text, iPosition - 2);
\\ here am adding it in the textbox
richTextBox1.Text = richTextBox1.Text.Insert(iPosition,FormatPattern);
\\ setting the current position
richTextBox1.Select(iPosition + FormatPattern.Length, 0);
richTextBox1.ResumeLayout(true);
\\ code ends
Thanks In Advance
kandy
kandy
|
|
|
|