473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

process communication between vb6 and c#

amw
Hello,

i have two applications (once in vb6 and once in c#) which have to
communicate together. They have to send and receive strings.

I used api-method sendmessage, but it doesn't work.

in vb:

Private Declare Function SendMessageByStr& Lib
"user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
ByVal _
lParam As String)

[..]

[code:1:5274173893]Call SendMessageByStr(hwndTarget, MessageId, 4,
"test")[/code:1:5274173893]

in C#:
[code:1:5274173893]unsafe protected override void WndProc(ref
Message m)
{
if (m.Msg == VB6_TO_CSHARP_MessageId.ToInt32())
{
try
{
string url = new
string((char*)(m.LParam.ToPointer()), 0,
m.WParam.ToInt32());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
base.WndProc(ref m);
} [/code:1:5274173893]

There is an exception by reading string. Has anyone sourcecode to send
and receive strings from VB6 and C# applications?

As an example project use this from codeproject (this project only
send normaly messages, no strings):
http://www.codeproject.com/dotnet/VB6andVBNETWindowMessages.asp

Can you help?

Sincerely,
Andre

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #1
4 1988
> There is an exception by reading string. Has anyone sourcecode to send
and receive strings from VB6 and C# applications?


you cannot send strings (pointers) in such way because the memory owned by
VB6 application cannot be accessed within the C# application. most probably
that's why you got an exception.

the simplest solution in your situation could be to send the string
char-after-char and end the transmission with some terminator. this way you
will not send a pointer but rather a long sequence of numbers. in vb6 code
just decompose the string into the sequence of digits (ASCII or any other
encoding) and in c# code compose the string back.

another solution would be to allocate some global memory (for example
GlobalAddAtom) at vb6 side and read the memory at C# side but I think it's
not worth an effort in your case.

Regards,
Wiktor Zychla
Nov 16 '05 #2
amw
> Wiktor Zychlawrote:
[quote:60f30c4742]There is an exception by reading string. Has anyone
sourcecode to send
and receive strings from VB6 and C# applications?

the simplest solution in your situation could be to send the string
char-after-char and end the transmission with some terminator. this
way you
will not send a pointer but rather a long sequence of numbers. in vb6
code
just decompose the string into the sequence of digits (ASCII or any
other
encoding) and in c# code compose the string back.
[/quote:60f30c4742]

Thanks for your answer! Have you got an example code for
(de-)composing strings to char?

Regards,
Andre

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #3
> Thanks for your answer! Have you got an example code for
(de-)composing strings to char?


I am afraid that this is a really basic question.

vb6: (decomposing)
Dim s as string ' string to send
Dim l as Long
For l = 1 To Len(s)
MsgBox Asc(Mid(s, l, 1))
Next

c#: (recreating string from byte[])

byte[] b; // received data
System.Text.Encoding.ASCII.GetString( b );
Nov 16 '05 #4
amw
>
I am afraid that this is a really basic question. :lol:


Ok, i know what you mean, now... It works.

It's a good idea (thanks!), but i hope there is an another way to send
strings in one message!

Regards,
Andre

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Berata | last post by:
Hello all, in VB6 we were able to create ActiveX-DLL's (In Process Components) and ActiveX-Exe's (Out of Process Components). We habe build up an application that exists of an main module...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
3
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2...
7
by: A.M | last post by:
Hi, What is the best way to implemet Inter Process Communication in .NET ? I developed two programs and I want to have them talk to each other. Thanks, Alan
4
by: archana | last post by:
Hi all, I want to do inter process communication in c#. I am having one application and one dll. What i want is load that dll at runtime. After loading that dll i want to send one event from...
0
by: ravindrag | last post by:
Hi, I am getting error SQL1131N during sqlj.install_jar(...). There is no useful message in the diag.log (even with diag level 4). I am giving the diag.log entries at the end of this posting...
6
by: ecir.hana | last post by:
Hi, let's say I have two scripts: one does some computations and the other one is a graphical front end for launching the first one. And both run in separate processes (front end runs and that it...
6
by: Kasper Lindberg | last post by:
Hi NG, How to do two-way-interprocess communication using java? Imagine a client/server setup where the client can request a number of functions to be performed by the server. Since the...
0
by: Fredrik Lundh | last post by:
projects.gg.aaron@gmail.com wrote: do you control the other process? can you make it listen to a local socket or a named pipe? </F>
0
by: dantz | last post by:
After reading all of the materials in msdn about interprocess communication now I am confused. I hope someone can give me some enlightment. I am developing a multithreaded client-server...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.