Click here to Skip to main content
16,004,564 members
Home / Discussions / C#
   

C#

 
QuestionRe: I want to get permission to interact with a file. Pin
Richard MacCutchan25-Jul-24 10:24
mveRichard MacCutchan25-Jul-24 10:24 
QuestionC# Trying to Create Custom Spell Checking Feature but keep running into roadblocks. Argument 1: cannot convert from 'System.IO.MemoryStream' to 'string' Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Tesseract.ImageFormat?' Pin
Texas-Tundra24-Jul-24 6:46
Texas-Tundra24-Jul-24 6:46 
AnswerRe: C# Trying to Create Custom Spell Checking Feature but keep running into roadblocks. Argument 1: cannot convert from 'System.IO.MemoryStream' to 'string' Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Tesseract.ImageForma Pin
OriginalGriff24-Jul-24 18:58
mveOriginalGriff24-Jul-24 18:58 
GeneralRe: C# Trying to Create Custom Spell Checking Feature but keep running into roadblocks. Argument 1: cannot convert from 'System.IO.MemoryStream' to 'string' Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Tesseract.ImageForma Pin
Texas-Tundra25-Jul-24 2:08
Texas-Tundra25-Jul-24 2:08 
GeneralRe: C# Trying to Create Custom Spell Checking Feature but keep running into roadblocks. Argument 1: cannot convert from 'System.IO.MemoryStream' to 'string' Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Tesseract.ImageForma Pin
OriginalGriff25-Jul-24 2:39
mveOriginalGriff25-Jul-24 2:39 
GeneralRe: C# Trying to Create Custom Spell Checking Feature but keep running into roadblocks. Argument 1: cannot convert from 'System.IO.MemoryStream' to 'string' Argument 2: cannot convert from 'System.Drawing.Imaging.ImageFormat' to 'Tesseract.ImageForma Pin
Texas-Tundra25-Jul-24 2:45
Texas-Tundra25-Jul-24 2:45 
GeneralRe: C# Trying to Create Custom Spell Checking Feature but keep ... Pin
OriginalGriff25-Jul-24 2:50
mveOriginalGriff25-Jul-24 2:50 
QuestionDPI issue when calling C# from C++ Pin
JudyL_MD23-Jul-24 11:05
JudyL_MD23-Jul-24 11:05 
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:
C#
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

AnswerRe: DPI issue when calling C# from C++ Pin
Richard Andrew x6423-Jul-24 12:08
professionalRichard Andrew x6423-Jul-24 12:08 
GeneralRe: DPI issue when calling C# from C++ Pin
JudyL_MD23-Jul-24 17:26
JudyL_MD23-Jul-24 17:26 
QuestionLog file advice? Pin
geomeo12318-Jul-24 15:12
geomeo12318-Jul-24 15:12 
AnswerRe: Log file advice? Pin
jschell19-Jul-24 13:24
jschell19-Jul-24 13:24 
GeneralRe: Log file advice? Pin
Richard Andrew x6420-Jul-24 14:37
professionalRichard Andrew x6420-Jul-24 14:37 
GeneralRe: Log file advice? Pin
geomeo12324-Jul-24 3:38
geomeo12324-Jul-24 3:38 
GeneralRe: Log file advice? Pin
jschell24-Jul-24 14:48
jschell24-Jul-24 14:48 
AnswerRe: Log file advice? Pin
Richard MacCutchan24-Jul-24 5:13
mveRichard MacCutchan24-Jul-24 5:13 
GeneralRe: Log file advice? Pin
Rob Philpott24-Jul-24 22:44
Rob Philpott24-Jul-24 22:44 
GeneralRe: Log file advice? Pin
jschell31-Jul-24 14:02
jschell31-Jul-24 14:02 
QuestionTables not appearing as classes Pin
Hesam emami9-Jul-24 23:17
Hesam emami9-Jul-24 23:17 
AnswerRe: Tables not appearing as classes Pin
Dave Kreskowiak10-Jul-24 2:56
mveDave Kreskowiak10-Jul-24 2:56 
GeneralRe: Tables not appearing as classes Pin
Hesam emami10-Jul-24 11:37
Hesam emami10-Jul-24 11:37 
GeneralRe: Tables not appearing as classes Pin
Dave Kreskowiak10-Jul-24 11:44
mveDave Kreskowiak10-Jul-24 11:44 
AnswerRe: Tables not appearing as classes Pin
RedDk10-Jul-24 14:15
RedDk10-Jul-24 14:15 
QuestionPrint and Print Preview of Web Page not Working Properly in Microsoft Edge Browser Pin
Fokwa Divine3-Jul-24 3:54
Fokwa Divine3-Jul-24 3:54 
AnswerRe: Print and Print Preview of Web Page not Working Properly in Microsoft Edge Browser Pin
jschell3-Jul-24 6:00
jschell3-Jul-24 6:00 

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.