Getting error while executing visual C++ GUI Program - forms

I'm getting error,
error C1113: #using failed on 'c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\system.core.dll'
When Executing following code...
MyForm.cpp
#include "Myform.h"
using namespace GUI;
[STAThreadAttribute]
int main(){
MyForm fm;
fm.ShowDialog();
return 0;
}
MyForm.h
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->Close();
}

Related

The variable parameter template --compiled error

The code is compiled through and run well on vs2015, but can not be compiled and report error on gcc/g++ 7.4.0, as follows:
gcc version 7.4.0 error
#include <iostream>
#include <memory>
class AA
{
public:
template<typename R, typename... Args>
R invoke(Args... args)
{
std::cout<< __FUNCTION__ << ":" << sizeof...(args) << std::endl;
return R();
}
template<typename R, typename... Args>
R call(Args... args)
{
return this->invoke<R, Args...>(args...);
}
};
template<typename T>
class BB
{
public:
BB(): lib(new T()){}
std::shared_ptr<T> lib;
};
template<typename T, typename... Args>
BB<T> make_module(Args... args)
{
BB<T> obj;
obj.lib->call<T, Args...>(args...);
return obj;
}
int main()
{
BB<AA> obj = make_module<AA>(1, 2, 3);
return 0;
}
You call member function template call on object which depends on template parameter T - BB<T> obj; you need to use template to indicate that call is member function template:
Replace
obj.lib->call<T, Args...>(args...);
by
obj.lib->template call<T, Args...>(args...);

Unable to catch STException in StringTemplate 4

I am unable to catch the STException thrown by the STGroupFile. This is a problem. I need to abort if the template is bad. To reproduce this problem, I have this incorrect template file called tmp.stg:
temp1(param1)::=<<
%if(param1)%
%param1:{%temp2(p)%}; separator"\n"%
%endif%
>>
And this groovy code to process it:
#!/usr/bin/env groovy
#Grab(group="org.antlr", module="ST4", version="4.0.8")
import org.stringtemplate.v4.STGroupFile;
import org.stringtemplate.v4.NumberRenderer;
public class Gex {
public static void main(String [] args) {
System.out.println("Processing...")
File fn = new File("tmp.stg")
STGroupFile group;
try {
group = new STGroupFile(fn.toString());
} catch (Throwable e) {
throw new Exception("Caught first exception");
}
try {
group.registerRenderer(Integer.class, new NumberRenderer());
} catch (Throwable e) {
throw new Exception("Caught second exception");
}
throw new Exception("You should not see this");
}
}
Gex.main()
When I run that script, I get an error message but I cannot catch the exception:
can't load group file file:tmp.stg
The error message comes from STGroupFile.java:
throw new STException("can't load group file "+fileName, e);
But I am unable to catch this exception. How can I catch this exception and abort?
Following the advice of The ANTLR Guy, I extended the STErrorListener to throw an exception instead of printing a message to stderr. It looks like this:
File: lib/GexListener.groovy
import org.stringtemplate.v4.STErrorListener;
import org.stringtemplate.v4.misc.STMessage;
import org.stringtemplate.v4.misc.ErrorType;
class GexListener implements STErrorListener {
#Override
public void compileTimeError(STMessage msg) {
throw new Exception(msg.toString());
}
#Override
public void runTimeError(STMessage msg) {
if ( msg.error != ErrorType.NO_SUCH_PROPERTY ) { // ignore these
throw new Exception(msg.toString());
}
}
#Override
public void IOError(STMessage msg) {
throw new Exception(msg.toString());
}
#Override
public void internalError(STMessage msg) {
throw new Exception(msg.toString());
}
public void error(String s) { error(s, null); }
public void error(String s, Throwable e) {
System.err.println(s);
if ( e!=null ) {
throw new Exception(msg.toString());
}
}
}
Then the master script bin/gex.groovy looks like this:
#!/bin/bash
//usr/bin/env groovy -cp ${0%/*}/../lib "$0" "$#"; exit $?
#Grab(group="org.antlr", module="ST4", version="4.0.8")
import org.stringtemplate.v4.STGroupFile;
import org.stringtemplate.v4.NumberRenderer;
import GexListener
public class Gex {
public static void main(String [] args) {
System.out.println("Processing...")
File fn = new File("tmp.stg")
STGroupFile group;
GexListener listener = new GexListener();
group = new STGroupFile(fn.toString());
group.setListener(listener);
group.registerRenderer(Integer.class, new NumberRenderer());
System.out.println("You should not see this line")
}
}
Gex.main()
When it executes, there is a nasty side effect where the stacktrace is printed twice, but the program aborts before printing the last sentence "You should not see this line", which is the desired behaviour.
As you pointed out in a separate email: "I discovered that the exception is actually caught and not re-thrown. This happens inside STGroup.java:"
catch (Exception e) {
errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
}
Why not override the IOError function (or a function in the listener that it calls?) to just re-throw e?

crystal report print and export not working

I'm .net developer. now I'm working with crystal report. when I'm printing or exporting crystal report then print dialog open when I press Print, then no print operation occurs. This Print and Export not working at fire fox. only chrome support this functions. Is there extra code required for do this job.
---------------------------updated-----------------------------------------
at class declaration :
public partial class EndUser_FS_File_History : System.Web.UI.Page
{
ReportDocument reportdocument = null;
..........
at load crystal report:
reportdocument = new ReportDocument();
string connectionString = ConfigurationManager.ConnectionStrings["FileSystemConnectionString"].ConnectionString;
SqlConnectionStringBuilder SConn = new SqlConnectionStringBuilder(connectionString);
reportdocument.Load(Server.MapPath(#"~/Admin/UserReport.rpt"));
reportdocument.SetDataSource(myDataSet);
reportdocument.DataSourceConnections[0].SetConnection(SConn.DataSource, SConn.InitialCatalog, SConn.UserID, SConn.Password);
CrystalReportViewer1.ReportSource = reportdocument;
and at Page_Unload event:
protected void Page_Unload(object sender, EventArgs e)
{
if (reportdocument != null)
{
reportdocument.Close();
reportdocument.Dispose();
}
GC.Collect();
}
still problem occurs with large no of records:
The maximum report processing jobs limit configured by your system administrator has been reached.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The maximum report processing jobs limit configured by your system administrator has been reached.
Source Error:
Line 782: string connectionString = ConfigurationManager.ConnectionStrings["FileSystemConnectionString"].ConnectionString;
Line 783: SqlConnectionStringBuilder SConn = new SqlConnectionStringBuilder(connectionString);
Line 784: reportdocument.Load(Server.MapPath(#"~/Admin/UserReport.rpt"));
Line 785: reportdocument.SetDataSource(myDataSet);
Line 786: reportdocument.DataSourceConnections[0].SetConnection(SConn.DataSource, SConn.InitialCatalog, SConn.UserID, SConn.Password);
Source File: f:\EasyWeb\Admin\User_Management.aspx.cs Line: 784
Stack Trace:
[COMException (0x80041016): The maximum report processing jobs limit configured by your system administrator has been reached.]
CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options) +0
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options) +144
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +526
[CrystalReportsException: Load report failed.]
CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened() +621
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) +1969
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename) +186
Admin_User_Management.lbut_print_Click(Object sender, EventArgs e) in f:\EasyWeb\Admin\User_Management.aspx.cs:784
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
There are few steps:
Before Pageload, declare the report as
ReportDocument rpt = null;
protected void Page_Load(object sender, EventArgs e)
{
try
{
rpt= new ReportName; //this is the name of your report
// do all the logic here
}
catch()
{
}
}
protected void Page_Unload(object sender, EventArgs e)
{
if(rpt!=null)
{
rpt.Close();
rpt.Dispose();
}
GC.Collect();
}

native extension Dart

I'm trying to build a native extension in dart for postgresql. I have compiled the CC file in .o then in .so (shared object i guess). It's now named libpsql.so and I placed it in the the same directory as my .dart file. The first line of dart file is #import(dart-ext:libpsql); but it keeps telling me that the resources is unavailable.
My dart code
#library("psql");
#import("dart-ext:libpsql_dart");
class Database {
var mDb;
var mUser;
var mDbname;
var mPasswd;
var mHost;
var mPort;
var mTable;
//String toString() => "<PostgreSQL: $user#$_host:$_port/$_table>";
Database(host,user,passwd,dbname) : this.mUser = user, this.mHost = host, this.mPasswd = passwd, this.mDbname = dbname {
mDb = _connect(host,user,passwd,dbname);
}
}
_connect(host,user,passwd,dbname) native 'Connect';
And here is my C++ code.
#include <string.h>
#include <stdio.h>
#include <libpq-fe.h>
#include "dart_api.h"
Dart_NativeFunction ResolveName(Dart_Handle name, int argc);
DART_EXPORT Dart_Handle psql_dart_Init(Dart_Handle parent_library) {
if (Dart_IsError(parent_library)) return parent_library;
Dart_Handle result_code =
Dart_SetNativeResolver(parent_library, ResolveName);
if (Dart_IsError(result_code)) return result_code;
return Dart_Null();
}
Dart_Handle HandleError(Dart_Handle handle) {
if (Dart_IsError(handle)) Dart_PropagateError(handle);
return handle;
}
void Connect(Dart_NativeArguments args) {
Dart_EnterScope();
PGconn *conn;
const char *conninfo = "user=postgres;password=postgres;host=localhost;port=5432;dbname=reviewdb";
conn = PQconnectdb(conninfo);
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
PQfinish(conn);
}
Dart_Handle result = HandleError(Dart_NewInteger((int64_t) conn));
Dart_SetReturnValue(args, result);
Dart_ExitScope();
}
Dart_NativeFunction ResolveName(Dart_Handle name, int argc) {
assert(Dart_IsString8(name));
const char* cname;
Dart_Handle check_error = Dart_StringToCString(name, &cname);
if (Dart_IsError(check_error)) Dart_PropagateError(check_error);
Dart_NativeFunction result = NULL;
if (strcmp("Connect", cname) == 0) result = Connect;
Dart_ExitScope();
return result;
}
Html script include
<script type="application/dart" src="web/lib/psql.dart"></script>
<script type="application/dart" src="web/test_dart.dart"></script>
And the last, my compile command line :
g++ -fPIC --verbose -I/home/{linux user}/Documents/dart/dart-sdk/include/ -lpq -I/usr/include/postgresql -c psql_dart.cc
gcc -shared -Wl,-soname,libpsql.so -o libpsql.so psql_dart.o
After testing new code i commented my function Connect like this :
void Connect(Dart_NativeArguments args) {
Dart_EnterScope();
// PGconn *conn;
// const char *conninfo = "user=postgres password=postgres host=localhost port=5432";
// conn = PQconnectdb(conninfo);
//
// /* Check to see that the backend connection was successfully made */
// if (PQstatus(conn) != CONNECTION_OK)
// {
// fprintf(stderr, "Connection to database failed: %s",
// PQerrorMessage(conn));
// PQfinish(conn);
// exit(1);
// }
// PQfinish(conn);
Dart_Handle result = HandleError(Dart_NewInteger( 0));
Dart_SetReturnValue(args, result);
Dart_ExitScope();
}
The output :
worked?
Segmentation fault (core dumped)
And I still get the SegFault any idea?
My gdb stacktrace :
Starting program: /home/<user>/Documents/dart/dart-sdk/bin/dart test_dart.dart
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
worked?
Program received signal SIGSEGV, Segmentation fault.
dart::Api::NewHandle (isolate=0x948a40, raw=0x7ffff7f80021) at runtime/vm/dart_api_impl.cc:114
114 runtime/vm/dart_api_impl.cc: No such file or directory.
(gdb) bt
#0 dart::Api::NewHandle (isolate=0x948a40, raw=0x7ffff7f80021) at runtime/vm/dart_api_impl.cc:114
#1 0x000000000042e121 in dart::Dart_Invoke (target=<optimized out>, name=0x959b90, number_of_arguments=<optimized out>, arguments=<optimized out>) at runtime/vm/dart_api_impl.cc:3543
#2 0x00000000004097ee in main (argc=<optimized out>, argv=<optimized out>) at runtime/bin/main.cc:724
After playing around some with your code and getting the postgresql-dev-9.1 package installed this is where I am. Currently it still does not run, however it is due to a linking error not due to the import itself.
Note a change to your C++ file: I renamed your initialization function from: psql_dart_Init to just psql_Init
// libpsql.cc
#include <string.h>
#include <stdio.h>
#include <libpq-fe.h>
#include "dart_api.h"
Dart_NativeFunction ResolveName(Dart_Handle name, int argc);
DART_EXPORT Dart_Handle psql_Init(Dart_Handle parent_library) {
if (Dart_IsError(parent_library)) return parent_library;
Dart_Handle result_code =
Dart_SetNativeResolver(parent_library, ResolveName);
if (Dart_IsError(result_code)) return result_code;
return Dart_Null();
}
Dart_Handle HandleError(Dart_Handle handle) {
if (Dart_IsError(handle)) Dart_PropagateError(handle);
return handle;
}
void Connect(Dart_NativeArguments args) {
Dart_EnterScope();
PGconn *conn;
const char *conninfo = "user=postgres;password=postgres;host=localhost;port=5432;dbname=reviewdb";
conn = PQconnectdb(conninfo);
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
PQfinish(conn);
}
Dart_Handle result = HandleError(Dart_NewInteger((int64_t) conn));
Dart_SetReturnValue(args, result);
Dart_ExitScope();
}
Dart_NativeFunction ResolveName(Dart_Handle name, int argc) {
assert(Dart_IsString8(name));
const char* cname;
Dart_Handle check_error = Dart_StringToCString(name, &cname);
if (Dart_IsError(check_error)) Dart_PropagateError(check_error);
Dart_NativeFunction result = NULL;
if (strcmp("Connect", cname) == 0) result = Connect;
Dart_ExitScope();
return result;
}
And the following is my 1st dart file:
// psql.dart
#library("psql");
#import("dart-ext:psql");
class Database {
var mDb;
var mUser;
var mDbname;
var mPasswd;
var mHost;
var mPort;
var mTable;
//String toString() => "<PostgreSQL: $user#$_host:$_port/$_table>";
Database(host,user,passwd,dbname) : this.mUser = user, this.mHost = host, this.mPasswd = passwd, this.mDbname = dbname {
mDb = _connect(host,user,passwd,dbname);
}
}
_connect(host,user,passwd,dbname) native 'Connect';
And then the actual VERY minimal application (command line instead of dartium-based) to test it.
// test.dart
#import('psql.dart');
main() {
var database = new Database('localhost', 'mbutler', 'test', 'test');
if(database != null) {
print('worked?');
}
}
I used the following command to compile and link in one go and I it does work correctly. I segfault because I don't have a valid database to connect to but the following does load the native library properly:
g++ -O2 -DDART_SHARED_LIB -I/home/<user>/dart/dart-sdk/include -rdynamic -fPIC -shared libpsql.cc -lpq -I/usr/include/postgresql -o libpsql.so
(Thanks to dart-sqlite build script was able to piece together the linking I required)

c++CLI event handler's not triggered

I am just getting into c++ CLI and am running into a problem where some event handlers are called and some are not.
here is a list of my event handlers:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void exitToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void aboutToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show("Paul Madsen\nLab 13",
"About lab 13", MessageBoxButtons::OK,
MessageBoxIcon::Asterisk);
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
try
{
double tmp = Double::Parse(textBox1->Text);
}
catch(...)
{
textBox1->ResetText();
}
}
private: System::Void textBox2_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
try
{
double tmp = Double::Parse(textBox2->Text);
}
catch(...)
{
textBox2->ResetText();
}
}
private: System::Void textBox1_Enter(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Test",
"test", MessageBoxButtons::OK,
MessageBoxIcon::Asterisk);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
double tmp = (Double::Parse(textBox1->Text) - 32) * 5/9;
textBox2->Text = System::Convert::ToString(tmp);
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
double tmp = (Double::Parse(textBox1->Text) - 32) * 5/9;
textBox1->Text = System::Convert::ToString(tmp);
}
button1_Click works just fine but button2_Click is never triggered even though they are essentially the same. Why is that?
Look back toward the beginning of the source code file, inside InitializeComponent(). You should have no trouble seeing the button1->Click event handler assignment. Do you see the one for button2->Click?
Delete the button in the designer, add it back. Double click it. Or just leave it out, no point in having two buttons doing the same thing.