|
This message board is for managed and mixed-mode C++ programming only: Managed C++ in VC++.NET or C++/CLI. Please post all standard C++ programming questions in the Visual C++ board[^].
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Hi Friends,
I have been asked this below question in a interview related to MultiThreading/Synchronization
I don't have much expertise in the same area.
Please help me with the solution.
Thanks in Advance
Problem->
Develop a C++ program to demonstrate threading and synchronization.
Char code generated by main process on press of key. (int iChar = getch(); )
Application will accept key between 0 to 9 only.
Three threads are spawned by main process to display key pressed
Any one of the thread will display the Number key pressed and and Thread ID
If No key is pressed Threads will wait for input.
Process will be terminated if Key '0' is pressed.
|
|
|
|
|
Amrit Agr wrote: Please help me with the solution.
Exactly what help are you asking for? If you are expecting someone else to write the code for you, I am afraid you have come to the wrong place. And if you have no expertise in this area, why are you being interviewed for such a role?
Incidentally, your question has nothing to do with C++/CLI, it is should have gone to C / C++ / MFC Discussion Boards[^].
|
|
|
|
|
hey guys i am new here i need help you guys are pro i hope i am in right place i need some dll to call function like command console press key to call console then you type in it "hello guys" it will output hello guys as strings
how i wanna use that dll
load_library "Console.dll"
get_proc_address "Commands"
|
|
|
|
|
Are you sure you'd like to do it using some managed C++/CLI code?
Then show your code...
|
|
|
|
|
Just create a console application that reads a line of text and prints it back out, and you have the complete answer.
|
|
|
|
|
Google would have saved you a lot of time here - MS Learn | Create a C++ console app project[^]
As a basic you will have something like -
#include <iostream>
#include <string>
int main() {
std::string line;
std::cout << "Enter a line of text: ";
std::getline(std::cin, line);
std::cout << "You entered: " << line << std::endl;
return 0;
}
|
|
|
|
|
thank you very much sir for reply but i need dll file to use them i have no idea how to write codes in c++ i need dll to get job done you can write any code language just need .dll file
|
|
|
|
|
If you're asking for someone to write this code for you, that's not going to happen.
|
|
|
|
|
Yeah sorry, as Dave stated, not going to happen if you want someone to write your code for you, not how it works here on CP
|
|
|
|
|
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^>();
cli::array<Stream^>^ streams = gcnew cli::array<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();
}
}
}
}
|
|
|
|
|
I want to use the Win32Exception class in my C++/CLI DLL. The docs say it is located in the System::ComponentModel namespace.
But Intellisense is telling me that there is no ComponentModel namespace inside System .
And worse, there is no System.ComponentModel DLL to which to add a reference.
I'm stuck. How do I get the System::ComponentModel namespace and its classes into my DLL?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
you might try: Microsoft.Win32.Primitives.dll
There is conflicting / confusing information out there.
I've confirmed the above in C#.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thanks Gerry.
I have 125 copies of that file on my dev machine. Each one is a different size, date, version and in a different folder.
I think I'll work around not having that exact exception class for now.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
hi guys
im working on c++/ cli project and i need something like objectlistview of TreelistView so i can display treeview with multi columns
modified 22-Aug-23 5:13am.
|
|
|
|
|
|
devexpress doesnt support c++/cli
|
|
|
|
|
Sorry, but that was all I could find. You could probably do a more focused search, since you know your exact requirements.
|
|
|
|
|
Temblor wrote: cli project...TreelistView
So 'cli' is command line interface.
So a CUI for a tree list view?
My take is you have three options.
1. Get different requirements so it is not needed at all.
2. The tree is going to be very shallow. And probably very short. So roll your own.
3. This isn't going to work.
Why the third? For example sometimes I recurse a directory tree via the command line looking for files or even all files. I can certainly view that in a console but it is basically worthless because there is so much data. Even if I am just looking for one specific file I still need a search mechanism. So I route to a file and then use an editor to search.
But lets say you are not looking for a actual file system. So what is the growth rate of this tree? If it is shallow and small in 10 years rolling your own still works. And the users can use it. But if your growth rate is not small then in 10 years the users will have something they can't use.
If I was asked to do this and I already knew that the tree was not small then I would push back on the requirements. In writing (like email.) And if they insisted I would first make a copy of that email and my response. Then I would just roll my own (still not that hard.) It would be their problem when it was unusable. But I might use a demo with data from 10 years from now - just so they can see what is going to happen.
|
|
|
|
|
jschell wrote: So 'cli' is command line interface.
No. See .NET programming with C++/CLI | Microsoft Learn[^] for example. It's some bastardisation of "Interface to CLR (Common Language Runtime)".
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
let explain some inf
I succeed in displaying sql data in a treeView all i need now is another column so i can display another data like (balance) in it
something like objectListView
it's not for showing system files
btw I saw some devs made what you taking about (file system in treeView) in C++ / MFC
|
|
|
|
|
jschell wrote: cli project...
So 'cli' is command line interface. The forum, title, and indeed the question specifically stated c++/cli, which is the C++ version of code that compiles into .NET IL.
modified 23-Aug-23 4:23am.
|
|
|
|
|
|
"Columns" are an illusion. If you only have "one column / item / field" (that you can identify), concatenate multiple fields together (as strings) with padding and / or a "separator" (e.g. "|")
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|