Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

how to pass lots of data from unmaged to manage code using CCW

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lightdoll - 30 Mar 2008 16:18 GMT
hello everyone

i want to send lots of data from unmanaged to mange code using CCW.

i have made this kind of code with variant, but it was slow..

for example

because i have to make variant type like safearray, before send variant to
manage code.

so there is loop to make variant type..

how can i solve this kind of problem.

please..help me..
Willy Denoyette [MVP] - 30 Mar 2008 18:07 GMT
> hello everyone
>
> i want to send lots of data from unmanaged to mange code using CCW.

Please define "unmanaged" code! What language is the client written in? Is
this a late bound or early bound scenario?
What do you call a lot of data?
Why do you use COM to transfer "lots of data"? COM was not designed to be
used as a data transfer protocol!

> i have made this kind of code with variant, but it was slow..

What do you call slow, how did you measure, on what OS and HW platform?
what were your expectations?

> for example
>
> because i have to make variant type like safearray, before send variant to
> manage code.

What makes you think you need a variant type?

> so there is loop to make variant type..

Hmm..., posting some code might help us to understand the issue.

> how can i solve this kind of problem.
>
> please..help me..

First we need you to answer the above questions.

Willy.
lightdoll - 31 Mar 2008 01:50 GMT
hello willy..

i am using c++ for client,

ok i wrote how to make my software..

i want to use net remote for server.

so i alredy made a server using Net Remote.

i want to send lots of data from client that is C++.

so i need to make Net Client of Remote using C#.

a client of c++ will send the Net Client have Net Remote.

so i need to convert net client to com for using C++.

do you have any idea to send lots of data from client to server using Net
Remote

any function.

> > hello everyone
> >
[quoted text clipped - 29 lines]
>
> Willy.
Willy Denoyette [MVP] - 31 Mar 2008 09:51 GMT
From what I understand, you have the following scenario:

(A) C++ <-- COM --> (B) C# <--- .NET remoting ---> (C) C#
and you say it is slow when passing a lot of data, right?

Well, I can't help you if you don't answer all of the questions asked
previously, notably the following question are key:

How did you measure?
What (results) did you measure?
What did you expect?
What are you requirements?
What data types are you passing?
COM interop:
   Is this an in-proc , or out-proc server scenario?
   What types do you pass from A to C?
   What's the size of the data?
.NET remoting:
   What's the "distance" between B and C (same machine , local network,
WAN, ...)?
   What's the protocol used?
   What kind of formatter do you use?

Willy.

Sorry, but I can't help you if you don't answer the questions asked
previously.
> hello willy..
>
[quoted text clipped - 54 lines]
>>
>> Willy.
lightdoll - 31 Mar 2008 15:47 GMT
hello willy..

thank you for your reply.

(A) C++ <-- COM --> (B) C# <--- .NET remoting ---> (C) C#
= > yes, i want to make my program like above.
= > i want to exchange data from win32, and C++.
How did you measure?
=> i wrote a time in cosole at remote server after Server received data from
client.
What (results) did you measure?
=>time...
What did you expect?
What are you requirements?
What data types are you passing?
=> i made a structure like below
=> typedef structure strValue
{
int Count;
char *chName;
char *chAddress;
char *price;
enum enKind;
}
=> i want to send the struture 10000 Numbers for 100ms from client to server

> COM interop:
>     Is this an in-proc , or out-proc server scenario?
=> before i made out-of-process with singleton by atl.
=> but today i have made new one with in-process using C#.

> ..NET remoting:
>     What's the "distance" between B and C (same machine , local network,
> WAN, ...)?
=> different machine and local network.

What's the protocol used?
=> tcp/ip

What kind of formatter do you use?
=> binary.

can i ask you soemthing?
i have made in-process using C# today.
i passed variant between c++ and C#.
so i have to prepare variant  type in c++.

can i pass structure from c++ to C#.
because if i can send structure from c++ to C#.
that is better than send variant from c++ to C#

thank you very much ...

> From what I understand, you have the following scenario:
>
[quoted text clipped - 81 lines]
> >>
> >> Willy.
Willy Denoyette [MVP] - 31 Mar 2008 23:48 GMT
Well, from what I understood, I can say that you don't need to make it that
complicated and slow.
The first option is to get rid of the .NET remoting part, and use DCOM as
protocol, to do this you have to:
- Derive a class from System.EnterpriseServices.ServicedComponent and
register the class (using regsvcs.exe) to run as a COM+ server type
application (out-proc).
- Export a proxy, for this application, using COM+ admin (run dcomcnfg.exe).
- Install the proxy (an MSI file) on the client machine(s).
- COM clients and .NET clients can now call the COM+ server application on
the remote server.
In order to reduce the marshaling overhead you'll have to specify your data
structure at the server (C#) like this:

   [Guid("your own private guid here")]
   [ComVisible(true)]
   public struct strValue
   {
       public int count;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
       public string chName;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
       public string chAddress;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
       public string price;
       public int enKind;
   }

Adapt the SizeConst values to suit your needs, note that I assume your char
fields have a fixed length.

The above declarations will export the structure in the tlb file with the
string fields declared as:

unsigned char chName[64];
..
};

At the server (C++) you need to:
- import the typelib created when running regsvcs.exe above using VC++
"import" directive.
       #import "your_server.tlb" no_namespace
- To get at the record description (the above structure)  you'll have to
call GetRecordInfoFromGuids , and pass the recordInfo in the call to
SafeArrayCreateEx, something like this....

 strValue *pstrValue = NULL;
 IRecordInfo *precordInfo = NULL;
 HRESULT hr = GetRecordInfoFromGuids( __uuidof(__SomeClass),
                                        1, 0,  0,  __uuidof(strValue),
                                        &pLoadRecordInfo );
// set the array bounds...
// and create the sa
 LPSAFEARRAY psastrValue = SafeArrayCreateEx(VT_RECORD, 1, rgsabound,
precordInfo );
..
 hr = SafeArrayAccessData(psastrValue ,
reinterpret_cast<PVOID*>(&pstrValue ));
 // fill the array with data.. using
 // and detach when done
 SafeArrayUnaccessData(...)
 call the server passing the array as argument.

Note that your requirements of 10000 structures per second cannot be
guraranteed, you'll have to measure, but with a structure size 200 bytes and
a fast reliable and not congested network (>= 100Mbps),  it should be
possible to pass 10000 * 200 byte structures over DCOM .

The second option is to get rid of both COM and .NET remoting, and go for a
socket based client/server solution, this is the fastest solution, but you
loose quite a bit offered by the COM+ infrastructure, you need to write more
code, and you need to marshal the structure yourself, but as the structure
is quite simple, this shouldn't be an big issue.

Willy.

> hello willy..
>
[quoted text clipped - 141 lines]
>> >>
>> >> Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.