Does anyone know how to use _set_invalid_parameter_handler with Delphi XE7 or later? See MSDN Article
Oops, it seems I should probably have given more context. I'm trying to load a C DLL that wraps a Matlab-based DLL. This worked before when I was using Delphi 2007, but fails now with XE7. I get these messages in the Event Log:
Module Load: RunChecker.dll. No Debug Info. Base Address: $10000000. Process myapp.exe (12304)
Module Load: libRunChecker.dll. No Debug Info. Base Address: $02A30000. Process myapp.exe (12304)
Module Load: mclmcrrt7_17.dll. No Debug Info. Base Address: $02A40000. Process myapp.exe (12304)
Module Load: PSAPI.DLL. No Debug Info. Base Address: $75420000. Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Debug Output:
Invalid parameter passed to C runtime function.
Process myapp.exe (12304)
Thread Start: Thread ID: 7192. Process myapp.exe (12304)
I'm trying to figure out what is causing these errors, and my search led to the above, but perhaps it is wrong? But I'm trying to get some insight into where the failure is introduced. Any thoughts/suggestions most appreciated!
_set_invalid_parameter_handler is part of the MSVC runtime. It's not something that you call directly from Delphi code because your Delphi code doesn't link to the MSVC runtime.
If you do wish to call _set_invalid_parameter_handler you should do so from the code that links to the MSVC runtime. In your case that would be your C DLL.
All that said, almost certainly the problem relates to the Char and PChar types. In Delphi 2007 they are aliases to AnsiChar and PAnsiChar respectively. In Delphi 2009 and later they are aliases to WideChar and PWideChar respectively.
Related
When an error occurs in my Delphi XE5 application, in my exception handler I am trying to get Jedi Code Library's JCLDebug.pas to show any parameters of method calls listed on the stack. I was hoping to get this information in a similar way to the way the Delphi IDE shows this information in its Call Stack debug window when you break during an exception, like this:
TestForm.DoSomething('A Test Parameter')
TestForm.TTestForm.DoSomethingClick($DF935B0)
VCL.Controls.TControl.Click
In my error handler, I get this a result similar to this with no parameter information:
[00F9701D]{Test.exe} TestForm.DoSomething$qqrx20System.UnicodeString (Line 138, "TestForm.pas")
[005E358B]{TestMonitor.exe} Vcl.Controls.TControl.Click$qqrv (Line 7340, "Vcl.Controls.pas")
I have initialised my error handling by calling during the units initialization section:
JclStackTrackingOptions:=JclStackTrackingOptions + [stStack, stRawMode];
JclStartExceptionTracking;
Then when the exception handler is invoked, I call the following to get the call stack strings:
JclLastExceptStackListToStrings(FErrors, True, False, False);
Is it possible to get the parameters the methods were called with using JCLDebug?
I have a C++ CORBA server which implements an interface throwing a user defined exception.
I am easily able to catch the specific exception when client and server are both implemented in C++ (tested using both TAO orb and omniORB).
But when I invoke the same method from Erlang (using orber), the exception appears as generic exception and not as specific user defined exception.
To test this I just used a simple IDL -
interface Messenger {
exception cirrus_error{
short error_code;
string error_desc;
};
boolean send_message(in string user_name,
in string subject,
inout string message) raises (cirrus_error);
};
If both server and client are in C++ - the exception I get is (for testing I coded it to always throw the user exception)
CORBA exception: cirrus_error (IDL:Messenger/cirrus_error:1.0)
But when invoked via Erlang - I get -
** exception throw: {'EXCEPTION',{'UNKNOWN',[],1330446337,'COMPLETED_MAYBE'}}
in function corba:raise/1
Do I need to do something special while stating Orber application to enable the correct behaviour?
Edit - This is how I call server from erlang -
On Erlang prompt, this is what I do -
1> orber:jump_start().
2> O = corba:string_to_object(IORStr).
3> 'Messenger':send_message(O, "s", "t", "f").
** exception throw: {'EXCEPTION',{'UNKNOWN',[],1330446337,'COMPLETED_MAYBE'}}
in function corba:raise/1
You need to register your IDL definitions into the orber interface repository (IFR) before invoking the method. If your IDL file is named messenger.idl, for example, compiling it creates oe_messenger.erl, which provides the oe_register/0 function. Calling it registers information about your user-defined exception into the IFR, which orber's CDR decoding uses to be able to properly decode any responses containing that exception:
1> orber:jump_start().
...
2> ic:gen(messenger).
Erlang IDL compiler version 4.4
ok
3> make:all().
Recompile: Messenger
Recompile: Messenger_cirrus_error
Recompile: oe_messenger
oe_messenger.erl:65: Warning: function oe_get_top_module/4 is unused
oe_messenger.erl:91: Warning: function oe_destroy_if_empty/2 is unused
up_to_date
4> oe_messenger:oe_register().
ok
5> M = corba:string_to_object(IORStr).
...
6> 'Messenger':send_message(M, "a", "b", "c").
** exception throw: {'EXCEPTION',{'Messenger_cirrus_error',"IDL:Messenger/cirrus_error:1.0",
1234,"yep, an error"}}
in function corba:raise/1 (corba.erl, line 646)
Update: The reason this extra IFR registration step is needed in orber, while rarely if ever being necessary in C++ ORBs, is due to some flexibility in the CORBA specification and also to C++ ORB development traditions. The original CORBA specification was in part a compromise between static and dynamic language camps. The dynamic camp insisted on the IFR being in the spec as they needed it for retrieving type information at runtime (and clearly they got their wish, since it's always been a part of CORBA), but the static camp assumed the IFR was unnecessary since all necessary type information could be encoded in C/C++ code generated from IDL definitions. The C++ ORB development community has traditionally followed the code generation approach and treated the IFR as an optional runtime component, and the C++ ORBs used in this question retrieve information about the user-defined cirrus_error exception from generated stubs and skeletons. But ORBs written in other languages, such as Smalltalk and Erlang, have chosen to use the IFR as a normal component of the ORB runtime, and so they require registration of type information into the IFR in order for it to be available to the ORB runtime. It would definitely be possible in Erlang, though, to generate information about user-defined exceptions into stubs/skeletons and have the runtime retrieve it from there.
While I DoFile:
Lua luaVM = new Lua();
luaVM.DoFile("test.lua");
This is the error I got.
An unhandled exception of type 'LuaInterface.LuaException' occurred in LuaInterface.dll
Additional information: error loading module 'mytestlib' from file '.\mytestlib.dll':
%1 is not a valid Win32 application.
The dll is I made, It works when I call this lua from LFW(lua for Windows).
Do I need something like a environment variables? (I added the lua/5.1 folder to EV)
I am trying to compare the performance of a specific F# benchmark running on .NET and Mono 2.10.2 (Windows 7, 64-bit). I took the Spectral-Norm benchmark from the Benchmarks Game followed the traditional SO advice of using System.Diagnostics.StopWatch for benchmarking C# and added the lines 4, 89-90, and 93-95 at this link. I compiled this code in Visual Studio 2010 (For runtime 4.0, not client profile, any CPU, with optimize code and tail calls turned on). The compiled code runs just fine on .NET (including inside VS), but when I run the .exe on Mono with "mono shootout_spectralnorm.exe" I get the following error (repeated in the fssnip.net link):
Unhandled Exception: System.TypeInitializationException: An exception was thrown
by the type initializer for System.Diagnostics.Stopwatch ---> System.InvalidPro
gramException: Invalid IL code in System.Diagnostics.Stopwatch:.cctor (): method
body is empty.
--- End of inner exception stack trace ---
at Program.main (System.String[] args) [0x00000] in <filename unknown>:0
The strange thing is, when I remove the lines I had added (lines 4, 89-90, and 93-95, which relate to the timing part of the benchmark), the error goes away on Mono, and it acts just like it does on MS .NET. This is just baffling me. I set all of the referenced assemblies in VS to be copied locally, so they should be visible to Mono, but there could be some precedence issue with different assemblies in the GAC that have the same name as the ones in the local folder. Has anyone encountered this issue or a similar one, especially on Windows Mono? If so, or if you think you know how this problem could be fixed, I hope you can help me resolve it.
Reference Assemblies do not (often) have code - they are API signatures only (enough info for the compiler to reference them at design-time/compile-time). You need to copy the runtime assemblies, not the reference assemblies, in order to run it. (You'll often find the runtime assemblies in the GAC.)
Here are measurements for FSharp-2.0.0.0 spectral-norm #2 (Intel Q6600 quad-core, MS Vista 32 bit)
fsc CPU s Elapsed s
500 0.281 0.337
3000 4.883 1.453
5500 15.85 4.212
2.10.2 CPU s Elapsed s
500 0.343 2.222
3000 4.836 3.361
5500 15.912 6.153
C:/Mono-2.10.2/bin/mono.exe C:/FSharp-2.0.0.0/bin/fsc.exe --platform:x86
--optimize+ --out:spectralnorm.exe spectralnorm.fsharpmono-2.fs
C:/Mono-2.10.2/bin/mono.exe --gc=sgen spectralnorm.exe 5500
Now the benchmarks game spectral-norm on MS Vista demo, includes F# on Mono.
I've been testing some D2006 code using Rave reports on a virtual machine and have found the app hangs when I generate a PDF report if there is no printer installed. The hang occurs here:
exception message : The application seems to be frozen.
main thread ($108):
005c5e62 +106 MyApp.exe RpRPTF SimpleTextWidth
006198f7 +31b MyApp.exe RpMemo TMemoBuf.GetLine
0061a44a +086 MyApp.exe RpMemo TMemoBuf.MemoLinesLeft
005cba28 +014 MyApp.exe RpBase TBaseReport.MemoLines
00672e8e +072 MyApp.exe MyAppReports PrintReportParagraph
00677f73 +acb MyApp.exe MyAppReports PrintSummaryReportBody
0066b208 +010 MyApp.exe MyAppMainForm TMainForm.RvSystemSummaryReportPrint
005c6f35 +015 MyApp.exe RpBase TBaseReport.PrintEvent
005c8066 +03a MyApp.exe RpBase TBaseReport.Execute
0060a299 +125 MyApp.exe RpSystem TRvSystem.GenerateReport
0060a52a +07e MyApp.exe RpSystem TRvSystem.Execute
0067d364 +0ac MyApp.exe MyAppReports DoPrintSummaryReport
0067d64d +1d5 MyApp.exe MyAppReports ProduceReports
0066e966 +1e6 MyApp.exe MyAppProcessing ProcessMyAppData
0066ab9b +0d7 MyApp.exe MyAppMainForm TMainForm.DoProcessData
and no doubt is something to do with a page width of zero confusing the code that is calculating how many lines it can fit across the page or some such.
The thing is I'm writing a PDF - not printing - so I can't see why not having a printer should trip this code up (Acrobat Reader is installed). If I install a printer it behaves. Why do I need a printer installed (the app could be installed on a workstation without a printer installed - having an error message that says: "You can't generate a PDF report unless you install printer" seems a bit clunky) ?
This is a long-standing bug in Rave Reports. It has to do with no default printer being installed. I'll look for links to old Borland/CodeGear forum posts (CodeNewsFast doesn't seem to be responding right now). There was a problem with it making an assumption about a printer being present. I don't know if it's been fixed in the most recent versions of Rave. (D2006 was quite a while back.)
If I remember correctly, the solution was to install the text driver to a "mock" printer. This allows Rave to continue to function.