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 / .NET Framework / CLR / November 2003

Tip: Looking for answers? Try searching our database.

interop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ZhangZQ - 01 Nov 2003 15:10 GMT
I created a ocx that has a method,

[id(5), helpstring("????Test1")] void Test1(VARIANT* a);

the implementation is
void Cocx030820Ctrl::Test1(VARIANT* a)
{
try
{
 //see here
AFX_MANAGE_STATE(AfxGetStaticModuleState());

ST_PRINT* m;
 //get data
m=(ST_PRINT*)a;
CString s;
s.Format("%d,%d,%s,%c",m->i,m->l,m->s,m->mSTRU1.c);
 MessageBox(s);
}
catch(...)
{
 MessageBox("f");
}
}

and the ST_PRINT definition is

#ifndef IOPRINT
   #define IOPRINT
   typedef struct
   {
unsigned char a[11];
unsigned char b[9];
char c;
   }STRU1;

   typedef struct
   {
unsigned char Tran[11];
unsigned char TermId[9];
STRU1 mSTRU1;
char c;
int i;
long l;
double d;
char s[10];
   }ST_PRINT;

#endif

My question is how to call the Test1 method in C#
   //ST_PRINT
   object obj=new object();
                                  how can I set the field value of obj.
   axocx0308201.Test1(ref b3);

Thank you very much!
Mattias Sj?gren - 03 Nov 2003 20:37 GMT
>the implementation is
>void Cocx030820Ctrl::Test1(VARIANT* a)
[quoted text clipped - 7 lines]
>  //get data
> m=(ST_PRINT*)a;

These kinds of hacks might work in C++, but not in C#. Why do you make
the parameter type a VARIANT* when it really isn't?

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

ZhangZQ - 03 Nov 2003 23:00 GMT
Dear Mattias,

It is necessary, because that OCX is the third party product, I have to use
it but can not change it, is it possible to do that?

Thank you very much!

ZhangZQ

> >the implementation is
> >void Cocx030820Ctrl::Test1(VARIANT* a)
[quoted text clipped - 12 lines]
>
> Mattias
Mattias Sj?gren - 19 Nov 2003 12:39 GMT
>It is necessary, because that OCX is the third party product, I have to use
>it but can not change it, is it possible to do that?

Only if you change the managed definition of the method to take an
IntPtr or a ST_PRINT& parameter instead.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


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.