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 / Managed C++ / April 2006

Tip: Looking for answers? Try searching our database.

How to convert C# out parameter to C++?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nick - 18 Apr 2006 21:44 GMT
For example:

   public static void FillRow(Object obj, out SqlDateTime timeWritten, out
SqlChars message, out SqlChars category, out long instanceId)
Tamas Demjen - 18 Apr 2006 22:04 GMT
>     public static void FillRow(Object obj, out SqlDateTime timeWritten, out
> SqlChars message, out SqlChars category, out long instanceId)

public:
   static void FillRow(
      Object ^ obj,
      [Out] SqlDateTime % timeWritten,
      [Out] SqlChars ^ % message,
      [Out] SqlChars ^ % category,
      [Out] long % instanceId);

I believe SqlDateTime is a value class, and SqlChars is a ref class. You
only need the caret for ref classes. The % symbol means pass by reference.

Tom
nick - 18 Apr 2006 22:36 GMT
Thanks, after add % and [Out] (seems it works fine without [Out] too?). The
code finally works.

However, when debugging, I keep get:

Cannot find either column "dbo" or the user-defined function or aggregate
"dbo.MyUDF", or the name is ambiguous.

> >     public static void FillRow(Object obj, out SqlDateTime timeWritten, out
> > SqlChars message, out SqlChars category, out long instanceId)
[quoted text clipped - 11 lines]
>
> Tom
nick - 18 Apr 2006 22:37 GMT
Btw, the code:

#include "stdafx.h"

using namespace System;
using namespace System::Data;
using namespace System::Data::Sql;
using namespace System::Data::SqlTypes;
using namespace Microsoft::SqlServer::Server;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;

// select dbo.MyUDF()
// go

public ref class AddNewUDF
{    
public:
   [SqlFunctionAttribute(
       FillRowMethodName = "FillRow",
       TableDefinition = "Message nvarchar(20), Category nvarchar(10),
instanceId Int"//
       )]
    static IEnumerable^ MyUDF()
    {
       DataTable dt;
       dt.Columns->Add("Test");
       dt.Rows->Add(1);
       return dt.Rows;
    }

   static void FillRow(Object obj, [Out] SqlChars^ % message, [Out]
SqlChars^ % category, [Out]long % instanceId)
   {
       message = gcnew SqlChars("Test");
       category = gcnew SqlChars("Test");
       instanceId = 212;
   }
};
nick - 18 Apr 2006 22:50 GMT
Never mind, Sorry I used wrong testing SQL statement.
Thanks very much.

> Thanks, after add % and [Out] (seems it works fine without [Out] too?). The
> code finally works.
[quoted text clipped - 19 lines]
> >
> > Tom
Tamas Demjen - 18 Apr 2006 23:57 GMT
> Thanks, after add % and [Out] (seems it works fine without [Out] too?).

C#: void f(ref int x);
same as
C++: void f(int% x);

C#: void f(out int x);
same as
C++: void f([Out] int% x);

The only difference is the [Out] attribute, which I think is mainly used
to determine the marshalling strategy. The [Out] attribute suggests that
the function doesn't use the argument as an input, it is strictly an
output, so it only needs to be marshalled in one direction. If you omit
[Out], it suggests that the function reads AND writes the given
argument, and therefore it must be marshalled back and forth. The
difference may not be important in a desktop application, but in a Web
service (or any distributed system) you might want to pay attention to
these details, in order to avoid unnecessary network traffic.

Example:

void GetValue([Out] int% x) { x = 10; }
// x is written only

void AddValue(int% x) { x = x + 10; }
// x is read and written

Tom
David Anton - 20 Apr 2006 01:50 GMT
BTW, 'long' in C# is Int64 in C++/CLI, not 'long'.
Signature

David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

> >     public static void FillRow(Object obj, out SqlDateTime timeWritten, out
> > SqlChars message, out SqlChars category, out long instanceId)
[quoted text clipped - 11 lines]
>
> Tom

Rate this thread:







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.