Click here to Skip to main content
15,887,083 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
PinnedThe C++ / CLI is for managed and mixed-mode C++ programming only Pin
Chris Maunder9-Jan-06 9:36
cofounderChris Maunder9-Jan-06 9:36 
QuestionMultiThreading/Synchronization related problem Pin
Amrit Agr15-Apr-24 7:22
Amrit Agr15-Apr-24 7:22 
AnswerRe: MultiThreading/Synchronization related problem Pin
Richard MacCutchan15-Apr-24 21:46
mveRichard MacCutchan15-Apr-24 21:46 
GeneralNeed Help (Command Console) Pin
Mahek Thapa30-Mar-24 5:17
Mahek Thapa30-Mar-24 5:17 
GeneralRe: Need Help (Command Console) Pin
Victor Nijegorodov30-Mar-24 9:32
Victor Nijegorodov30-Mar-24 9:32 
GeneralRe: Need Help (Command Console) Pin
Richard MacCutchan30-Mar-24 22:34
mveRichard MacCutchan30-Mar-24 22:34 
GeneralRe: Need Help (Command Console) Pin
Andre Oosthuizen31-Mar-24 23:07
mveAndre Oosthuizen31-Mar-24 23:07 
GeneralRe: Need Help (Command Console) Pin
Mahek Thapa10-Apr-24 20:53
Mahek Thapa10-Apr-24 20:53 
GeneralRe: Need Help (Command Console) Pin
Dave Kreskowiak11-Apr-24 3:49
mveDave Kreskowiak11-Apr-24 3:49 
GeneralRe: Need Help (Command Console) Pin
Andre Oosthuizen11-Apr-24 6:29
mveAndre Oosthuizen11-Apr-24 6:29 
QuestionConvert From C# to C++/CLI Pin
Paramu19731-Mar-24 14:26
Paramu19731-Mar-24 14:26 
Hi, I try to convert from C# to C++/Cli. I have a small application in C#. When I try to print the RDLC report directly to printer, I found a c# online-codes.

public static void Print(this LocalReport report, PageSettings pageSettings)
{
    string deviceInfo =
        $@"<DeviceInfo>
            <OutputFormat>EMF</OutputFormat>
            <PageWidth>{pageSettings.PaperSize.Width * 100}in</PageWidth>
            <PageHeight>{pageSettings.PaperSize.Height * 100}in</PageHeight>
            <MarginTop>{pageSettings.Margins.Top * 100}in</MarginTop>
            <MarginLeft>{pageSettings.Margins.Left * 100}in</MarginLeft>
            <MarginRight>{pageSettings.Margins.Right * 100}in</MarginRight>
            <MarginBottom>{pageSettings.Margins.Bottom * 100}in</MarginBottom>
        </DeviceInfo>";
    Warning[] warnings;
    var streams = new List<Stream>();
    var pageIndex = 0;
    report.Render("Image", deviceInfo,
        (name, fileNameExtension, encoding, mimeType, willSeek) =>
        {
            MemoryStream stream = new MemoryStream();
            streams.Add(stream);
            return stream;
        }, out warnings);
    foreach (Stream stream in streams)
        stream.Position = 0;
    if (streams == null || streams.Count == 0)
        throw new Exception("No stream to print.");
    using (PrintDocument printDocument = new PrintDocument())
    {
        printDocument.DefaultPageSettings = pageSettings;
        if (!printDocument.PrinterSettings.IsValid)
            throw new Exception("Can't find the default printer.");
        else
        {
            printDocument.PrintPage += (sender, e) =>
            {
                Metafile pageImage = new Metafile(streams[pageIndex]);
                Rectangle adjustedRect = new Rectangle(e.PageBounds.Left - (int)e.PageSettings.HardMarginX, e.PageBounds.Top - (int)e.PageSettings.HardMarginY, e.PageBounds.Width, e.PageBounds.Height);
                e.Graphics.FillRectangle(Brushes.White, adjustedRect);
                e.Graphics.DrawImage(pageImage, adjustedRect);
                pageIndex++;
                e.HasMorePages = (pageIndex < streams.Count);
                e.Graphics.DrawRectangle(Pens.Red, adjustedRect);
            };
            printDocument.EndPrint += (Sender, e) =>
            {
                if (streams != null)
                {
                    foreach (Stream stream in streams)
                        stream.Close();
                    streams = null;
                }
            };
            printDocument.Print();
        }
    }
}
For the above code I convert it like the below, but still need to improve the conversion, any helps please. Thanks. And my converted codes.
public: static System::Void Print(LocalReport^ report, PageSettings^ pageSettings){
             String^ deviceInfo =
                 $@"<DeviceInfo>
                 <OutputFormat>EMF< / OutputFormat>
                 <PageWidth>{pageSettings->PaperSize->Width * 100}in< / PageWidth>
                 <PageHeight>{pageSettings->PaperSize->Height * 100}in< / PageHeight>
                 <MarginTop>{pageSettings->Margins->Top * 100}in< / MarginTop>
                 <MarginLeft>{pageSettings->Margins->Left * 100}in< / MarginLeft>
                 <MarginRight>{pageSettings->Margins->Right * 100}in< / MarginRight>
                 <MarginBottom>{pageSettings->Margins->Bottom * 100}in< / MarginBottom>
                 < / DeviceInfo>";
                 cli::array<Warning^>^ warnings = gcnew cli::array<Warning^>();
                 //Warning[] warnings;
                 cli::array<Stream^>^ streams = gcnew cli::array<Stream^>();
                 //var streams = new List<Stream>();
                 int pageIndex = 0;
                 report->Render("Image", deviceInfo, (name, fileNameExtension, encoding, mimeType, willSeek) = > {
                 MemoryStream^ stream = gcnew MemoryStream();
                 streams->Add(stream);
                 return stream;
                 }, out^ warnings);
                 for each(Stream^ stream in streams) {
                     stream->Position = 0;
                     if (streams == nullptr || streams->Length == 0) {
                         throw gcnew Exception("No stream to print.");
                     }
                     else {
                         PrintDocument^ printDocument = gcnew PrintDocument();
                         printDocument->DefaultPageSettings = pageSettings;
                         if (!printDocument->PrinterSettings->IsValid)
                             throw gcnew Exception("Can't find the default printer.");
                         else
                         {
                             printDocument->PrintPage += (sender, e) = >
                             {
                                 Metafile^ pageImage = gcnew Metafile(streams[pageIndex]);
                                 Rectangle^ adjustedRect = gcnew Rectangle(e->PageBounds->Left - (int)e->PageSettings->HardMarginX, e->PageBounds->Top - (int)e->PageSettings->HardMarginY, e->PageBounds->Width, e->PageBounds->Height);
                                 e->Graphics->FillRectangle(Brushes->White, adjustedRect);
                                 e->Graphics->DrawImage(pageImage, adjustedRect);
                                 pageIndex++;
                                 e->HasMorePages = (pageIndex < streams->Count);
                                 e->Graphics->DrawRectangle(Pens->Red, adjustedRect);
                             };
                             printDocument->EndPrint += (Sender, e) = >
                             {
                                 if (streams != nullptr)
                                 {
                                     foreach(Stream^ stream in streams)
                                         stream->Close();
                                     streams = nullptr;
                                 }
                             };
                             printDocument->Print();
                         }
                     }
                 }
         }

QuestionTrying to Add System::ComponentModel Pin
Richard Andrew x649-Dec-23 10:10
professionalRichard Andrew x649-Dec-23 10:10 
AnswerRe: Trying to Add System::ComponentModel Pin
Gerry Schmitz9-Dec-23 10:55
mveGerry Schmitz9-Dec-23 10:55 
GeneralRe: Trying to Add System::ComponentModel Pin
Richard Andrew x649-Dec-23 13:25
professionalRichard Andrew x649-Dec-23 13:25 
AnswerRe: Trying to Add System::ComponentModel Pin
Richard MacCutchan9-Dec-23 21:11
mveRichard MacCutchan9-Dec-23 21:11 
QuestionTreelistView c++/cli Pin
Temblor21-Aug-23 23:05
Temblor21-Aug-23 23:05 
AnswerRe: TreelistView c++/cli Pin
Richard MacCutchan22-Aug-23 0:09
mveRichard MacCutchan22-Aug-23 0:09 
GeneralRe: TreelistView c++/cli Pin
Temblor22-Aug-23 3:57
Temblor22-Aug-23 3:57 
GeneralRe: TreelistView c++/cli Pin
Richard MacCutchan22-Aug-23 4:03
mveRichard MacCutchan22-Aug-23 4:03 
AnswerRe: TreelistView c++/cli Pin
jschell22-Aug-23 6:41
jschell22-Aug-23 6:41 
GeneralRe: TreelistView c++/cli Pin
Peter_in_278022-Aug-23 17:20
professionalPeter_in_278022-Aug-23 17:20 
GeneralRe: TreelistView c++/cli Pin
Temblor22-Aug-23 20:54
Temblor22-Aug-23 20:54 
GeneralRe: TreelistView c++/cli Pin
Richard MacCutchan22-Aug-23 21:48
mveRichard MacCutchan22-Aug-23 21:48 
GeneralRe: TreelistView c++/cli Pin
jschell23-Aug-23 6:47
jschell23-Aug-23 6:47 
AnswerRe: TreelistView c++/cli Pin
Gerry Schmitz23-Aug-23 5:49
mveGerry Schmitz23-Aug-23 5:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.