Porting from C++ to C# Syntax Question 
Author Message
 Porting from C++ to C# Syntax Question

Im trying to call a C++ dll that has the following declaration:

extern "C" _declspec(dllimport) int ClogH(HANDLE hClogObj, int iTraceLevel,
LPCTSTR szMessage, ...) ;

My question is, how does this call translate to C#. Its pretty simple with
the exception of the last parameter(s) in the list "..."

My C# code to import the DLL looks like:

      [DllImport("clog.dll")]

      static extern int ClogH(int hFile, int iTraceLevel, string strMessage,
[]);

Anyone have any ideas how I translate the "..." into C#?

Thanks,

Alex C.



Sun, 02 Jan 2005 04:26:56 GMT  
 Porting from C++ to C# Syntax Question
what exactly does the "..." represent, or is that what your trying to
determine?


Sun, 02 Jan 2005 04:31:19 GMT  
 Porting from C++ to C# Syntax Question
Have you tried just using an object[]  in place of the (...) in c#?
thanks - bill

Quote:
> Im trying to call a C++ dll that has the following declaration:

> extern "C" _declspec(dllimport) int ClogH(HANDLE hClogObj, int
iTraceLevel,
> LPCTSTR szMessage, ...) ;

> My question is, how does this call translate to C#. Its pretty simple with
> the exception of the last parameter(s) in the list "..."

> My C# code to import the DLL looks like:

>       [DllImport("clog.dll")]

>       static extern int ClogH(int hFile, int iTraceLevel, string
strMessage,
> []);

> Anyone have any ideas how I translate the "..." into C#?

> Thanks,

> Alex C.



Sun, 02 Jan 2005 05:02:10 GMT  
 Porting from C++ to C# Syntax Question

Quote:
> what exactly does the "..." represent, or is that what your trying to
> determine?

It indicates a variable argument list in C/C++.  I'm a C# novice, but it
would appear the params keyword provides similar functionality.


Sun, 02 Jan 2005 05:15:40 GMT  
 Porting from C++ to C# Syntax Question


Quote:
> Im trying to call a C++ dll that has the following declaration:

> extern "C" _declspec(dllimport) int ClogH(HANDLE hClogObj, int
iTraceLevel,
> LPCTSTR szMessage, ...) ;

c# supports variable-length parameter lists.

example:

public void AQQ( string text, int a, params object[] args)
{
    int i;
    for ( i=0; i< args.GetLength(0), i++)
    {
        // do whatever you want with the parameters
    }

Quote:
}

the clue keywords are

params object[] args

Regards,
Wiktor Zychla



Sun, 02 Jan 2005 14:38:24 GMT  
 Porting from C++ to C# Syntax Question
'vararg' not (officially) supported in C#, read:
  http://groups.google.com/groups?selm=ek%24XBoALCHA.1008%40tkmsftngp10

--
  NETMaster  (Thomas Scheidegger)
  http://www.cetus-links.org/oo_csharp.html

Quote:

> > what exactly does the "..." represent, or is that what your trying to
> > determine?
> It indicates a variable argument list in C/C++.  I'm a C# novice, but it
> would appear the params keyword provides similar functionality.



Sun, 02 Jan 2005 15:53:36 GMT  
 Porting from C++ to C# Syntax Question


Quote:
> > > what exactly does the "..." represent, or is that what your trying to
> > > determine?

> > It indicates a variable argument list in C/C++.  I'm a C# novice, but it
> > would appear the params keyword provides similar functionality.

> 'vararg' not (officially) supported in C#, read:
>   http://groups.google.com/groups?selm=ek%24XBoALCHA.1008%40tkmsftngp10

Did you read my post before you replied to it?  The 'params' keyword appears
to be an official, supported C# keyword which seems (again, to this C#
novice) to the same type of functionality as the '...' construct in C++.

http://msdn.microsoft.com/library/en-us/csref/html/vclrfparams.asp



Mon, 03 Jan 2005 03:45:16 GMT  
 Porting from C++ to C# Syntax Question
varargs isn't supported. Your best solution would be to wrap the function
using the managed extensions to C++, and convert the interface to something
easier to use from C#.

--
Visit the C# product team at http://www.gotdotnet.com/team/csharp

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Im trying to call a C++ dll that has the following declaration:

> extern "C" _declspec(dllimport) int ClogH(HANDLE hClogObj, int
iTraceLevel,
> LPCTSTR szMessage, ...) ;

> My question is, how does this call translate to C#. Its pretty simple with
> the exception of the last parameter(s) in the list "..."

> My C# code to import the DLL looks like:

>       [DllImport("clog.dll")]

>       static extern int ClogH(int hFile, int iTraceLevel, string
strMessage,
> []);

> Anyone have any ideas how I translate the "..." into C#?

> Thanks,

> Alex C.



Mon, 03 Jan 2005 03:45:32 GMT  
 Porting from C++ to C# Syntax Question

Quote:




> > > > what exactly does the "..." represent, or is that what your trying
to
> > > > determine?

> > > It indicates a variable argument list in C/C++.  I'm a C# novice, but
it
> > > would appear the params keyword provides similar functionality.

> > 'vararg' not (officially) supported in C#, read:
> >   http://groups.google.com/groups?selm=ek%24XBoALCHA.1008%40tkmsftngp10

> Did you read my post before you replied to it?  The 'params' keyword
appears
> to be an official, supported C# keyword which seems (again, to this C#
> novice) to the same type of functionality as the '...' construct in C++.

> http://msdn.microsoft.com/library/en-us/csref/html/vclrfparams.asp

It was pointed out to me that the original poster was not looking to *port*
the function in question to C# (as the subject would seem to indicate), but
rather was looking to interoperate with the existing C++ function.  Mea
culpa.


Mon, 03 Jan 2005 04:05:21 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Over 3,000 syntax errors from cstdlib and cstdio when porting to VS.Net C++

2. Porting from C++ to C#?

3. Newbie porting EventSample.cs to ASP.NET

4. porting from C++ to C#

5. Porting code from C++ to C#

6. Porting C++ code to C#.

7. Porting C++ code to C#

8. C# vs. C++ syntax

9. C# type conversion syntax question

10. Porting or not porting, that is the question!!!

11. Porting or not porting, that is the question!!!

12. Function syntax (was: Porting Windows Apps to Wine)

 

 
Powered by phpBB® Forum Software