|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I'm putting this in C# since it's an issue with initializing NET...
I have a WinForm DLL that is written to be DPI-aware. It is called from both C# and C-based executables. There is an intermediate mixed-mode C / CLR / C# DLL between the executable and the Winform DLL that calls from C to Managed C++ to C# to launch the WinForm DLL. Both the C and the C# exe are also DPI-aware (as appropriate for their language) and both display correctly.
Here's the logic flow.
C or C# exe:
- calls into the intermediate's cdecl entry point using the usual LoadLibrary / GetProcAddress mechanism
intermediate mixed-mode DLL:
- C entry point makes a call to an internal CLR function
- CLR function marshals the parameters, does a gcnew on a C# class and calls its single member function
- C# member function:
Assembly targetAssembly = Assembly.Load (File.ReadAllBytes ("path to winform dll");
Type startType = targetAssembly.GetType ("startupNameSpace.startupClass", true);
object startLib = startType.InvokeMember ("", BindingFlags.CreateInstance, null, null, new object[0]);
startType.InvokeMember ("startupMethod", BindingFlags.InvokeMethod, null, startLib, new object[] { marshalled parameters } );
WinformDll:
- startupNamespace.startupClass is NOT a form, just a plain C# class
- startupMethod creates a parameterized thread, sets the apartment state to STA and starts the thread passing the marshalled parameters
- the thread instantiates the first WinForm class with the parameters and calls ShowDialog
So, here's the problem.
When run from a C# exe, the DPI logic works correctly. I have a C#exename.exe.config file in the same directory with the exe that contains a "startup" section with my framework version number and a "System.Windows.Forms.ApplicationConfigurationSection" section containg the DpiAwareness key with a value of PerMonitorV2.
When run from a C exe, the WinForm display is incorrect in the exact places where I have my DPI-handling logic. It's obvious from the display that the property DeviceDpi is incorrect for every form. The research I've done leads me to believe that the .NET environment created to run my winform assembly is missing the dpi awareness flag that is set in the config for the C# exe. I've tried adding a config file with all the different name permuations using the C exe name, the intermediate dll name, the Winform dll name, "exe" and "dll". Nothing is picked up by the NET subsystem that is automatically loaded for me.
So the question is -- how do I force the NET subsystem to see a config that sets the DPI state?
Judy
Also, I have tried the solution to fix an incorrect DeviceDpi when an exe is first run on a secondary monitor (in the form's OnHandleCreated, call GetDpiForWindow, scale it, resize the form, and send a WM_DPICHANGED with that retrieved dpi). Putting this in the first form displayed does not fix the incorrect display.
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
.NET Framework or .NET Core?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Framework 4.7.2
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I'm writing a program that allows users to send commands to various serial devices. Most of the commands are "Button" orientated. By that I mean they press a button and everything is done for them; however I have a textbox that allows them to type in manual commands should there be something I don't have a button for that they really want to happen. I'm thinking about logging what commands they are typing in order to improve my program so that I can add other buttons that will help make life easier all. I'm wondering if there's a way to do that possibly on Github so that I can retrieve basically over web. Or if there's a better way to do it? I'm currently working in Csharp/WPF. I'm also thinking about logging some try/catch handler errors, so that I can analyze software bugs too, but I'm not too bothered about that right now.
|
|
|
|
|
First of course be aware of your user base. You are collecting information about them by doing that and there might be customer relation problems with that. And legal ones as well.
Other than that all your are doing is collecting data remotely from an application. There are many ways to do that.
geomeo123 wrote: if there's a way to do that possibly on Github
As in that there is a library for that? Or that you want the data stored on Github? For the first I am certain there is. As for the second that wouldn't be my choice.
geomeo123 wrote: thinking about logging some try/catch handler errors
You should create a code API that logs the following
- location. File/method.
- Text that describes what it is
- Additional information. This would be where you put exceptions, including stack traces.
Then you call that where ever you want.
There are specific libraries that provide 'logging'. In C# I have used log4net and Nlog.
That provides the API that I mentioned ready to go. It does not however provide the 'destination'. I know you can find addins to log to databases. I suspect others.
Another problem you will have is that since your application is remoting pushing data then someone might do something malicious to abuse your system. Basically you need to figure they will attempt this. So at a minimum you need to provide credentials. Although that probably is not enough. You might want to throttle as well so if they hack your app they can't just start blasting away.
There are services that provide APIs that collect data also.
|
|
|
|
|
jschell wrote: There are many ways to do that If I may, but you didn't mention what any of them are. I too have been asking myself this question and I'm very interested to know what other people think.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I use Winform and I use Entity Framework to communicate with the database and I use the MSSQL database and when I want to connect the SQL database to the Visual Studio program, the table Those that exist in my database are not present as classes in the Visual Studio program
|
|
|
|
|
If you're talking about using the Data Sources tab in Visual Studio to connect to the database, and you're using Entity Framework, you're doing it wrong. The Visual Studio designers will not create classes for Entity Framework. You have to write the classes yourself.
|
|
|
|
|
If I connect the data base to Visual Studio and create my own classes, will Visual Studio connect my classes to the tables in the data base?
|
|
|
|
|
It appears you have no idea what Entity Framework is or how it works, correct?
Visual Studio isn't going to do anything for you when using Entity Framework, nor should you rely on it. Using the designers in Visual Studio hides a bunch of details from you that makes learning how to interact with databases more difficult to learn. You don't need anything from Visual Studio to work with databases.
|
|
|
|
|
Downloads: Generic Database Access[^]
This a HUGE Codeproject article which, from the looks of things (quick scroll through the .zip content), is likely to give out many C# programming secrets wrt SQL Server (even) with no further sacrifice of time searching on your part.
Generic Database Access[^]
|
|
|
|
|
I have a strange issue I am experiencing with a web app. Typically, the user right clicks on the web page and click Print. He views the document in preview and then decides how to print it.
On Chrome, everything works fine
On Microsoft Edge, It only works if you right click the web page at the top of the page. If you scroll down to the bottom of the page before you right click and select print, the printed document is not formatted properly. The print preview is also not formatted properly. See screen shots below:
On Chrome - (User right click from bottom of page)
You can see the title of the app, title of the report, report run date etc
Report Issue - Chrome.PNG - Google Drive[^]
On MS Edge - (User right click from bottom of page)
The preview starts at some random data as shown below. Title of the app, title of report etc are not shown in the preview and printed version.
Report Issue - MS Edge.PNG - Google Drive[^]
As you can see from the above screen shots, Chrome is displayed properly. MS Edge only displays like that if I right click on the web page from the top of the page without scrolling down
Below is my code sample:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Physician Activity Report</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link href="~/lib/font-awesome/css/all.css" rel="stylesheet" />
<link href="~/css/mycss.css" rel="stylesheet" media="print" />
</head>
Below is the content of mycss.css
@media print {
.col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
.col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
float: left;
}
.col-md-12 {
width: 100%;
}
.col-md-11 {
width: 91.66666666666666%;
}
.col-md-10 {
width: 83.33333333333334%;
}
.col-md-9 {
width: 75%;
}
.col-md-8 {
width: 66.66666666666666%;
}
.col-md-7 {
width: 58.333333333333336%;
}
.col-md-6 {
width: 50%;
}
.col-md-5 {
width: 41.66666666666667%;
}
.col-md-4 {
width: 33.33333333333333%;
}
.col-md-3 {
width: 25%;
}
.col-md-2 {
width: 16.666666666666664%;
}
.col-md-1 {
width: 8.333333333333332%;
}
}
h5 {
color: darkblue;
}
What can I do to get this to work properly on MS Edge ? Is it a CSS issue ?
|
|
|
|
|
No idea what the answer is but I did upvote the question because someone down voted it and without explanation. Seems like a reasonable question to me.
Perhaps they wanted you to post in a different forum but didn't feel like explaining that.
|
|
|
|
|
Yeah. It is a strange issue that our users recently brought up. Most users use MS Edge. I don't know what angle to analyze from. It is a .NET Core web app.
|
|
|
|
|
I use Edge as a secondary browser when Firefox fails to display a dark background with light foreground because it (Edge) and it's settings remain at default. Nothing there in a contextual right-click and print (apparently CTrl+P also) fails when the target format is .PDF; so I suggest ... printing from the saved .pdf document instead of printing to .png.
|
|
|
|
|
Hi @RedDK, thanks for your input. Yeah CTrl+P also fails. Like I said in the question even the generated PDF is not formatted properly for MS Edge. Why is it that it works if I right click and click print from the top of the web page but as soon as I scroll down and do the same action it doesn't work in MS Edge ? What can I do to fix it ? What code do I need to add? Why don't I experience same issue in Chrome?
|
|
|
|
|
Perhaps your reticense to post actual code instead of showing images through links is what's keeping me from seeing what could possibly be wrong here. I can right-click and Print this as-is ... with no difficulties.
|
|
|
|
|
I found the answer:
It's a known issue in Edge version 126. The fix has been included in Stable 126.0.2592.81, which had been released on June 27, 2024. Please install the latest Edge Stable version 126.0.2592.81 (Official build) and test again.
|
|
|
|
|
Hello everyone,
I try to connect a pc to some esp32 arudino boards using tcp sockets
the idea is that on the each esp board I open a server that accapt the pc( client ) request and also a client that is used to do all data traffic between the pc and esp
the pc and the board use the some router as AP i wrote some thing like that using Jyhton
Now i want to do the some for other project but on the PC I run a VS2022 C# program that connect to the esp boards but i don't know how to do it .
Can someone show me the road ( an example will be great )
Regards Doron
|
|
|
|
|
You are going to have to give us a lot more detail than that - we have no idea what you have tired, where you are stuck, or what help you might need - if you have a working example, most developers should be able to alter it to fit the new circumstances, so we are at a loss to know what you expect from us that will help you get there.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi
May be is was not clear , I don't have code written yet.
i want to get the idea how to create and manage many client sockets on my pc so i can select the socket i will send the data to by using the ip or other index
Doron
|
|
|
|
|
Doesn't matter how you 'think' about the design the following is true.
For TCP sockets there is always a 'server' and a 'client'.
The 'server' creates a listener port and waits for a connection.
The 'client' opens a socket to the server. So the client is the one that initiates the connection.
After a connection is created either side can send and receive requests. Although often the client is the one that sends most requests.
The above also means that the server must have an addressable IP address. Probably in your situation that will not matter but it does mean you will need to figure out what the servers IP address is.
-----------------------------
Now for your actual code whether your want the pc or arudino to be the server is up to you. (I know very little about the second but I expect it can act as both a server and client.)
However I suggest that you start your learning experience using the PC only. So you will have two programs that run on your PC. One is the server. One is the client.
You can google for examples of writing code exactly like that in C#.
After you have tested that a bit then I suggest again only on the PC that you simulate what you want to actually do using the sample code. So for example if you want to send a specific command to the arudino then add code to do that in the PC code (client probably) and then respond in a pseudo way on the other side of the PC code.
You might also want to figure out how to analyze problems while you are developing this.
So for example you might do the following
- PC server code to simulate arudino
- Command received: Health check. Returns 'ok'
- PC client code to send command
- Command send: Health check
- Use Console.WriteLine() to write the command to send (all information)
- Use socket code to send it
- Use socket code to recieve response
- Use Console.WriteLine to write the response (all information.)
You should also experiment with what happens when the IP address is wrong and what happens if the server is not running.
-----------------------------------------------------------------------
As additional suggest for quite a bit in the future for a full application relying on Console.WriteLine() is not workable. So investigate 'logging'. You should not do this until you are comfortable with sockets.
|
|
|
|
|