|
In managed code , i send a message to native application :
Dim s As String = "text that i want to send"<br />
Dim GC As GCHandle = GCHandle.Alloc(s)<br />
SendMessage( hwnd , MsgId , wParam , GC )<br />
GC.Free()
In native code , i want to display a message box with text got from above message :
LRESULT WndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )<br />
{<br />
MessageBox(hWnd, (LPTSTR)lParam, L"Caption", MB_OKCANCEL | MB_ICONQUESTION | MB_APPLMODAL);<br />
}
But i can not get text with : (LPTSTR)lParam
Please help me to know why this code doesn't work , and how to do it ?
Thank you
|
|
|
|
|
Hi,
within a single process you need to obtain a GCHandle with GCHandleType.Pinned
so the GC can not move the object anymore; then you get the pointer through
GCHandle.AddrOfPinnedObject, and that will be your lParam.
passing strings to another process does not work that way, since the pointer
only means something to the process that owns the string. More code is needed
to allocate, then write, memory in the other process.
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
|
|
|
|
|
Thank you , i will try to write "more code"
|
|
|
|
|
Hi, you may want to have a look at my TrayIconBuster article; it has an LP_Process
class that deals with this (it is in C#, same things can be done in VB.NET).
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
|
|
|
|
|
Thank you again
|
|
|
|
|
Hi,
I want to make an encryptation to a string but the result to be places in a textbox.
I tried the cryptostream class but it work only with stream.
thanks
|
|
|
|
|
You should be able to write out the stream to a byte array and then convert the byte array to a string.
Here are some methods I have used, sorry they are in C# They should be easy to re-write in vb.net
public static String MemoryStreamToString(MemoryStream p_ms)
{
return MemoryStreamToString(p_ms, Encoding.Default);
}
public static String MemoryStreamToString(MemoryStream p_ms, Encoding p_encoding)
{
return ByteArrayToString(p_ms.GetBuffer(), p_encoding);
}
public static MemoryStream StringToMemoryStream(String p_string)
{
return StringToMemoryStream(p_string, Encoding.Default);
}
public static MemoryStream StringToMemoryStream(String p_string, Encoding p_encoding)
{
return new MemoryStream(StringToByteArray(p_string, p_encoding));
}
public static Byte[] StringToByteArray(string p_str)
{
return StringToByteArray(p_str, Encoding.Default);
}
public static Byte[] StringToByteArray(string p_str, Encoding p_encoding)
{
return p_encoding.GetBytes(p_str);
}
public static string ByteArrayToString(byte[] p_byteArray)
{
return ByteArrayToString(p_byteArray, Encoding.Default);
}
public static string ByteArrayToString(byte[] p_byteArray, Encoding p_encoding)
{
int numberOfBytes = p_byteArray.Length;
return p_encoding.GetString(p_byteArray, 0, numberOfBytes);
}
Hope that helps.
Ben
|
|
|
|
|
Hello friends.
Please tell me what the job of function (InstrReverse) and function (Instr)with examples.
Thank you so much.
|
|
|
|
|
<code>
if instr("read the help or google it","google") > 0 then
Success = true
else
PutSomeEffortInBeforePostingOnAForum = true
end if
if InStrReverse exists then
LookItUp = true
else
StopWastingOtherPeoplesTime = true
end if
</code>
-- modified at 9:07 Wednesday 15th August, 2007
You always pass failure on the way to success.
|
|
|
|
|
LOVE IT!
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
|
i need to make a scheduling system for a guesthouse. (9 rooms). i need a way to scroll through the database (Sql 2005) and view room bookings relative to dates and rooms.
Calendar function and rooms thanks!
|
|
|
|
|
Basically, you need to write a database, in SQL, and then you need to write a simple program that displays your information, and calls the database methods. Smells like homework to me.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a user input form in which user enters some rich text in a rich text box. I store the rtb1.rtf into database. Now all what I need is to concate all input i.e. concate rtf from all rows (in database) but what happens when the output appears the only text from the first row appears. But I need to prepare whole rtf document containing data from all rows. Please help me in this regard and also let me know if the scenario is not clear
Salman Sheikh
|
|
|
|
|
|
Thanx a lot sir but i am using SQL Server 2000 and using text type to store rtf. here comes exactly the same text returned by the Richtextbox control's rtf Property.
Also i couldn't read the complete article you told for i am not registered user of that site.
Salman Sheikh
|
|
|
|
|
hi
have you tried creating an invisible richtextbox and then apppeding the database rows to the richtectbox
sort of
for eachatabase row
RichTextBox1.Rtf = RichTextBox1.rtf + <db rows="" rtf="">
next
then at the end to get the plaintext just do
val = richtextbox1.text
not elegant but will probably work
HTH
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
first of all thanx everybody.
yes i tried the same way you told but this didn't work. the thing actually is that every record contains the rtf document start elements. so i removed it from every record but the first and i removed ending bracket from every record but the last and this worked well..
once again thanx a lot for your kind reply
Salman Sheikh
|
|
|
|
|
I'm writing an app in which a process(the vb .net component) is executed and a progressbar is updated simultaneously thru a do .. while loop . What i want to do is to add a cancel/stop button. In the stop button event code ,i've written code to 'kill' the running process . But when i execute the form ,the stop button (or for that matter any button) is not clickable,when the process and the do-while-loop code are running .Please Advice.
Regards,
Vivek
|
|
|
|
|
|
the control works only for c#,it doesn't work in vb,can u give me example code for creating threads.
|
|
|
|
|
I have come across the same situation you describe and using threads I coded it something like this:
<code>
Public scanInformThread As Threading.Thread
scanInformThread = New Threading.Thread(AddressOf Me.scanInformThreadProc)
scanInformThread.Priority = Threading.ThreadPriority.Lowest
scanInformThread.Start()
While scanInformThread.IsAlive = True
check if cancel button is pressed
if it is pressed then scanInformThreadProc.Abort()
Yadayada Blahblah
make a cuppa coffee
End While
Sub scanInformThreadProc()
Yadayada Blahblah
do something useful like surf the web
end sub
</code>
Please excuse the pseudocode.
Also note that this is not thread safe so you will need to put:
Control.CheckForIllegalCrossThreadCalls = False
at the beginning of your code to stop the compiler from whining at you.
I hope this helps.
Guy
-- modified at 8:02 Wednesday 15th August, 2007
-- modified at 8:06 Wednesday 15th August, 2007
You always pass failure on the way to success.
|
|
|
|
|
hey
you dont need to do the loop . just start the thread and end the function
then on the buttons onclick event do a scanInformThreadProc.Abort()
HTH
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
You're right.
I just hacked this out of my memory.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|
|
thanks , i will try this
|
|
|
|