The code below compiles but after clicking on first button it breaks with msg
Unhandled exception at 0x0133ae9a in deming.exe: 0xC0000005: Access violation writing location 0x014aedbd.
Is it a c++ error as i am novice or is it dragonsdk i use ?
//====================================================
// App.cpp
//====================================================
#include "DragonFireSDK.h"
#include <string.h>
int Picture;
int OnClick(int value)
{
char* image = "Images/image";
image = strcat(image,"_");
Picture = PushButtonAdd(image, 10, 100, OnClick, 1);
return 0;
}
void AppMain()
{
// Application initialization code goes here. Create the items / objects / etc.
// that your app will need while it is running.
Picture = PushButtonAdd("Images/Logo", 10, 100, OnClick, 1);
}
The reason of your problem is wrong imagination of what strcat does. It is appending second buffer to the first – in this case your first buffer is static, so appending to it obviously fails. You should use something like
Also don’ forget to
delete[] fullnameafter you are done with the buffer.You might find useful documentation for strcat (and other functions) in here
You migh also consider using C++ std::string, as they do it all for you, and if you need c-style strings, you can always get them via c_str() method.