|
What?? This is the Managed C++/CLI forum. This crash directly affects C++/CLI code. I'd think anyone that cares about successfully coding in C++/CLI will care about this. Thus, the post.
|
|
|
|
|
Hi
I am working on a C++ Project in which i am using some third party SDK to read some data. Some times few API's in that third party SDK are getting crashed such that my program getting terminated\crash.
So, instead of crash i want to handle those exceptions in the third party API's. May i know how to do handle them. I am using Visual studio 2015 and used exception handling too but unable to catch the exceptions thrown by third party API's.
Regards
Sampath
|
|
|
|
|
Contact the owners of the library for help. Unless you know exactly where the exceptions occur, and what they are caused by, you will find it very difficult to gather any meaningful information.
|
|
|
|
|
Thank You. As of now we are reporting the issues to the owners of the library and they are fixing and providing the fixes in their next release. But i cannot hold my work till their fix. Some how i need to proceed by excluding those exceptions in my code. Is it possible by any chance or any technique to skip those crashes and handling them in my code?
|
|
|
|
|
No idea, only the owners of the library can answer that question. And ignoring errors is probably the most dangerous thing you can do in any application.
|
|
|
|
|
You can add generic Catch block in your code for function which is calling that third party APIs and in catch you do nothing.But its just to avoid your application from getting crash, ideally you should not do it as it makes no sense.
~Sam
|
|
|
|
|
I am currently working on fixing a project for a client. A little information about the project first:
1. Originally developed in Visual Studio 2012 using xp_v110 build tools
2. Multiple projects in the solution
3. Currently updating/debugging in Visual Studio 2017 using VS 2015/xp_v140 build tools
4. Working on Windows 10
The application will run in debug mode, however if I just leave the application after starting the debug session (i.e. not opening/clicking on the application to open it as it starts minimized in the tray), the application crashes after 1-2 minutes.
Unfortunately the IDE is showing that the crash is taking place in chkstk.asm with the following message:
Exception thrown at 0x0064EDF9 in <<exe name="">>: 0xC00000FD: Stack overflow (parameters 0x00000000, 0x000A2000).
I have updated the exception settings to break when all C++ Exceptions are thrown, checked the box that says "Break when this exception type is thrown", and wrapped the initial method that runs in a try block, however I can never catch the error in the C++ code; it always occurs in the chkstk.asm file.
Any suggestions on how I can find out where in the C++ code the exception is occurring. Like I said, this is an update for a client and the original programmer is not available, and they never commented their code, so it is difficult enough trying to go through all this. Any help/suggestions would be greatly appreciated. Thanks in advance.
A black hole is where God tried to divide by zero.
There are 10 kinds of people in the world; those who understand binary and those who don't.
|
|
|
|
|
You need to get the stack trace at the time of the crash and walk back through it to find out who is using all the stack space.
|
|
|
|
|
You should make small memory dump using windows task manager. If you have application .pdb files and source files you can load windows dump file with Visual studio and debug it as managed code. If there are symbols debugging files (pdb) you can see thread`s stack in appropriate state.
|
|
|
|
|
I think this message was meant for the OP.
|
|
|
|
|
I suggest you launch the app in the debugger and then wait for ~20 seconds then break into the debugger. Most likely you'll see the a deep stack as it's in the midst of eating up stack space. That callstack should lead you to the issue.
|
|
|
|
|
please tell me what is going on in below code
if(curl)
{
curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&ret);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteFunction);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
curl_easy_cleanup(curl);
return 0;
}
curl_easy_cleanup(curl);
if(ret.find("Ok"))
{
char* r=new char[ret.length()+1];
strcpy(r,ret.c_str());
char* p=strtok(r,"|");
p=strtok(NULL,"|");
return atoi(p);
}
}
return 1;
}
|
|
|
|
|
It appears to use some third party library (curl ?) to obtain text input, find the first token and convert its text to an integer, which it then returns to the caller. I would suggest getting the documentation for the library and studying that.
|
|
|
|
|
|
i have a code for sms send my api provider is changed below mention is my code problem is what will return my new api vender so i can use that dll in my vfp application.
code
#include "stdafx.h"
#include "smsservice.h"
#include <string>
using namespace std;
size_t WriteFunction( char *ptr, size_t size, size_t nmemb, void *userdata)
{
string* s=(string*)userdata;
int i;
for(i=0;i<size*nmemb;i++)
{
s->push_back(ptr[i]);
}
return i;
}
int _declspec(dllexport) SendSms(LPCSTR userId,LPCSTR userPass,LPCSTR phoneNumber,LPCSTR smsText,LPCSTR senderId)
{
CURL* curl;
curl=curl_easy_init();
string ret;
string url="http://way2send.in/submitsms.jsp?Userid=";
char* esc=curl_easy_escape(curl,userId,strlen(userId));
url+=esc;
curl_free(esc);
url+="&UserPassword=";
esc=curl_easy_escape(curl,userPass,strlen(userPass));
url+=esc;
curl_free(esc);
url+="&PhoneNumber=";
esc=curl_easy_escape(curl,phoneNumber,strlen(phoneNumber));
url+=esc;
curl_free(esc);
url+="&Text=";
esc=curl_easy_escape(curl,smsText,strlen(smsText));
url+=esc;
curl_free(esc);
url+="&GSM=";
esc=curl_easy_escape(curl,senderId,strlen(senderId));
url+=esc;
curl_free(esc);
if(curl)
{
curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&ret);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteFunction);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
curl_easy_cleanup(curl);
return 0;
}
curl_easy_cleanup(curl);
if(ret.find("Ok"))
{
char* r=new char[ret.length()+1];
strcpy(r,ret.c_str());
char* p=strtok(r,"|");
p=strtok(NULL,"|");
return atoi(p);
}
}
return 1;
}
|
|
|
|
|
What is the question? And why have you posted this in the Managed C++/CLI section?
|
|
|
|
|
Your code looks like the native C++. So why did you post in the managed C++/CLI forum?
|
|
|
|
|
Your code looks like the native C++.
|
|
|
|
|
need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?
<pre>#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
typedef struct tagBITMAPFILEHEADER {
unsigned short bfType;
unsigned int bfSize;
short bfReserved1;
short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXpelsPerMeter;
int biYpelsPerMeter;
unsigned int biClrUses;
unsigned int biClrImportant;
} BITMAPINFOHEADER;
int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);
unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);
int main()
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
string str = "bitmap.bmp";
const char * nazwa_pliku = str.c_str();
ifstream ifs(nazwa_pliku, ios::binary) ;
if( !ifs.is_open() )
{
cout << "\nBlad otwarcia pliku";
return 0;
}
ofstream ofs("out.bmp", ios::binary);
int kursor = odczytajBFH(ifs, bfh);
kursor = odczytajBIH(ifs, bih, kursor);
zapiszBFH(ofs, bfh);
zapiszBIH(ofs, bih);
unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
int szerokosc = bih.biWidth;
int wysokosc = bih.biHeight;
unsigned char* obraz = odczytajDaneObrazu(ifs, rozmiar, kursor);
int **niebieski = new int*[wysokosc];
int **zielony = new int*[wysokosc];
int **czerwony = new int*[wysokosc];
for (int i = 0; i < wysokosc; i++ )
{
niebieski[i] = new int [szerokosc];
zielony[i] = new int [szerokosc];
czerwony[i] = new int [szerokosc];
}
odczytajRGB(obraz, niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc );
cout << "bfh.bfType: "<<bfh.bfType <<endl;
cout << "bfh.bfSize: "<< bfh.bfSize <<endl;
cout << "bfh.bfReserved1 "<<bfh.bfReserved1 <<endl;
cout << "bfh.bfReserved1 "<<bfh.bfReserved2 <<endl;
cout << "bfh.bfOffBits: "<<bfh.bfOffBits <<endl;
cout<<endl;
cout << "bih.biSize: "<<bih.biSize <<endl;
cout << "bih.biWidth: "<<bih.biWidth <<endl;
cout << "bih.biHeight: "<<bih.biHeight <<endl;
cout << "bih.biPlanes: " <<bih.biPlanes <<endl;
cout << "bih.biBitCount: " <<bih.biBitCount <<endl;
cout << "bih.biCompression: "<<bih.biCompression <<endl;
cout << "bih.biSizeImage: "<< bih.biSizeImage <<endl;
unsigned char * obraz2 = polaczRGB(niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc);
zapiszDaneObrazu(ofs, obraz2, rozmiar);
zwolnij_pamiec(obraz, niebieski, zielony, czerwony, wysokosc );
ifs.close();
system("pause");
return 0;
}
int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh)
{
ifs.read(reinterpret_cast<char *>(& bfh.bfType), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfSize), 4);
ifs.read(reinterpret_cast<char *>(& bfh.bfReserved1), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfReserved2), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfOffBits), 4);
return ifs.tellg();
}
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh)
{
ofs.write(reinterpret_cast<char *>(& bfh.bfType), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfSize), 4);
ofs.write(reinterpret_cast<char *>(& bfh.bfReserved1), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfReserved2), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfOffBits), 4);
}
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor)
{
ifs.seekg(kursor, ios::beg);
ifs.read(reinterpret_cast<char *>(& bih.biSize), 4);
ifs.read(reinterpret_cast<char *>(& bih.biWidth), 4);
ifs.read(reinterpret_cast<char *>(& bih.biHeight), 4);
ifs.read(reinterpret_cast<char *>(& bih.biPlanes), 2);
ifs.read(reinterpret_cast<char *>(& bih.biBitCount), 2);
ifs.read(reinterpret_cast<char *>(& bih.biCompression), 4);
ifs.read(reinterpret_cast<char *>(& bih.biSizeImage), 4);
ifs.read(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(& bih.biClrUses), 4);
ifs.read(reinterpret_cast<char *>(& bih.biClrImportant), 4);
kursor = ifs.tellg();
return kursor;
}
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih)
{
ofs.write(reinterpret_cast<char *>(& bih.biSize), 4);
ofs.write(reinterpret_cast<char *>(& bih.biWidth), 4);
ofs.write(reinterpret_cast<char *>(& bih.biHeight), 4);
ofs.write(reinterpret_cast<char *>(& bih.biPlanes), 2);
ofs.write(reinterpret_cast<char *>(& bih.biBitCount), 2);
ofs.write(reinterpret_cast<char *>(& bih.biCompression), 4);
ofs.write(reinterpret_cast<char *>(& bih.biSizeImage), 4);
ofs.write(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4);
ofs.write(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4);
ofs.write(reinterpret_cast<char *>(& bih.biClrUses), 4);
ofs.write(reinterpret_cast<char *>(& bih.biClrImportant), 4);
}
unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor)
{
ifs.seekg(kursor, ios::beg);
unsigned char *obraz = new unsigned char[rozmiar];
ifs.read(reinterpret_cast<char*>(obraz), rozmiar);
return obraz;
}
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar)
{
ofs.write(reinterpret_cast<char*>(obraz), rozmiar);
}
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony,
int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
int k = 0;
for (int i = 0; i < wysokosc; i++)
{for (int j = 0; j < szerokosc; j++)
{
niebieski[i][j]=obraz[k++];
zielony[i][j]=obraz[k++];
czerwony[i][j]=obraz[k++];
}
k+=zerowe_bajty;
}
}
unsigned char *polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
unsigned char * obraz = new unsigned char [rozmiar];
for (int k = 0; k < rozmiar; k++)
obraz[k] = 0;
int k = 0;
for (int i = 0; i < wysokosc; i++)
{for (int j = 0; j < szerokosc; j++)
{
obraz[k++]=niebieski[i][j];
obraz[k++]=zielony[i][j];
obraz[k++] = czerwony[i][j];
}
k+=zerowe_bajty;
}
return obraz;
}
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc)
{
for(int i = 0; i < wysokosc; i++)
{
delete [] niebieski[i];
niebieski[i] = NULL;
delete [] zielony[i];
zielony[i] = NULL;
delete [] czerwony[i];
czerwony[i] = NULL;
}
delete [] niebieski;
niebieski = NULL;
delete [] zielony;
zielony = NULL;
delete [] czerwony;
czerwony = NULL;
delete [] obraz;
obraz = NULL;
}
|
|
|
|
|
I don't know Polish so that it is really hard to retrace the code.
But you missed some points:- There are two versions of info headers with different sizes which can be identified using the
biSize member: BITMAPINFOHEADER and BITMAPV5HEADER
- When
biCompression is BI_BITFIELDS , these bitfields are stored after the info header.
- Your code supports only 24-bit RGB bitmaps. So you should check if the file is in that format (
biBitCount == 24).
You can read the pixel data from file offset bfOffBits with size biSizeImage which includes the padding bytes. But your code starts reading after the info header which is the location of the bitfields table or still within a BITMAPV5HEADER .
|
|
|
|
|
Dear friends,
I don't understand the below codes, please explain for me:
case 3:
{
system("cls");
do
{
found = 0;
printf("\n\n\t..Contact Search\n\t=================================\n\t...Name of Contact to search: ");
fflush(stdin);
scanf("%[^\n]",&querry);
l=strlen(querry);
fp=fopen("Contact.dll","r");
system("cls");
printf("\n\n::Search result for: 's'\n====================================\n", querry);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=list.name[i];
name[1]='\0';
}
}
if (stricmp(name,querry)==0)
{
printf("\n..::Name\t: %s\n..::Phone\t: %ld\n....::Address\t %s\n.....::Email\t:%s\n", list.name,list.ph,list.add,list.email);
found++;
if(found%4==0)
{
printf("Press any key to continue..");
getch();
}
}
if(found==0)
{
printf("\n..:No match found");
}
else
{
printf("\n....match(s) found!",found);
}https:
fclose(fp);
printf("\n.......Try again ? \n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}
while (ch==1);
}
break;
----------------------------------------------
while(fread....) --> what does this mean ?
if (stricmp(name,q .... --> what does it mean ?
Please explain for me , thank you very much!
Hieu
|
|
|
|
|
Hiếu Ngô wrote: while(fread....) --> what does this mean ? It means repeat the loop while that condition remains true. So if the fread function returns any value other than 1 the loop will terminate.
Hiếu Ngô wrote: if (stricmp(name,q. --> what does it mean ? It means compare two strings ignoring the case of characters. So "AbCd" will match "aBcD" or "abcd" etc.
Full details of these, and other functions, constructs etc., are in the language references on MSDN.
|
|
|
|
|
|
Hey all,
Here's some great news for everyone still doing C++/CLI coding! ReSharper C++ has added C++/CLI support. I'm eager to try this out!
Blog Post:
C++/CLI support comes to ReSharper C++[^]
John
|
|
|
|
|
in the code below i would like to know how the logic of finding the angle at a turn works.
int main()
{
RenderWindow app(VideoMode(640, 480), "Car Racing Game!");
app.setFramerateLimit(60);
Texture t1, t2;
t1.loadFromFile("images/background.png");
t2.loadFromFile("images/car.png");
Sprite sBackground(t1), sCar(t2);
sCar.setPosition(300, 300);
sCar.setOrigin(22, 22);
float x = 300, y = 300;
float speed = 0, angle = 0;
float maxSpeed = 12.0;
float acc = 0.2, dec = 0.3;
float turnSpeed = 0.08;
while (app.isOpen())
{
Event event;
while (app.pollEvent(event))
{
if (event.type == Event::Closed)
app.close();
if (Keyboard::isKeyPressed(Keyboard::Escape))
app.close();
}
bool Up = false, Right = false, Down = false, Left = false;
if (Keyboard::isKeyPressed(Keyboard::Up)) Up = true;
if (Keyboard::isKeyPressed(Keyboard::Right)) Right = true;
if (Keyboard::isKeyPressed(Keyboard::Down)) Down = true;
if (Keyboard::isKeyPressed(Keyboard::Left)) Left = true;
if (Up && speed < maxSpeed)
if (speed < 0) speed += dec;
else speed += acc;
if (Down && speed > -maxSpeed)
if (speed > 0) speed -= dec;
else speed -= acc;
if (!Up && !Down)
if (speed - dec > 0) speed -= dec;
else if (speed + dec < 0) speed += dec;
else speed = 0;
if (Right && speed != 0) angle += turnSpeed * speed / maxSpeed;
if (Left && speed != 0) angle -= turnSpeed * speed / maxSpeed;
x += sin(angle) * speed ;
y -= cos(angle) * speed ;
app.clear(Color::White);
app.draw(sBackground);
sCar.setPosition(x, y);
sCar.setRotation(angle * 180 / 3.141592) ;
sCar.setColor(Color::Red);
app.draw(sCar);
app.display();
}
return 0;
}
How the below logic works ?
Quote: if (Right && speed != 0) angle += turnSpeed * speed / maxSpeed;
if (Left && speed != 0) angle -= turnSpeed * speed / maxSpeed;
x += sin(angle) * speed ;
y -= cos(angle) * speed ;
Thank you
|
|
|
|
|