Debug Assertion Failed with rgbConverted.cpp - c++-cli

First saying, It's a duplicate question, but not the same problem.
When I run my code, this message is showing, but no error.
#pragma once
using namespace System::Drawing;
ref class rgbConvert
{
private:
System::Drawing::Bitmap^ grayImage;
System::Drawing::Bitmap^ bainaryImage;
System::Drawing::Bitmap^ rgbImage;
int xsize;
int ysize;
bool **BArray;
int **GrayArray;
int **binary;
FILE *fp;
static float coef01 = (float)0.2989;
static float coef02 = (float)0.5870;
static float coef03 = (float)0.1140;
public:
rgbConvert(System::Drawing::Bitmap^ im)
{
rgbImage = im;
xsize = rgbImage->Height;
ysize = rgbImage->Width;
}
rgbConvert(int height, int width)
{
xsize = height;
ysize = width;
}
int** getGrayImageArray ()
{
GrayArray = new int * [xsize];
for (int i = 0; i < xsize; i++ )
{
GrayArray[i] = new int[ysize];
}
for( int i = 0; i < this->xsize; i++ )
{
for ( int j = 0; j < this->ysize; j++ )
{
System::Drawing::Color^ clr = this->rgbImage->GetPixel(j, i);
int pixel = clr->ToArgb();
//int alpha = (pixel >> 24) & 0xff;// no need here
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
int grayC = int(coef01*red + coef02*green + coef03*blue);
GrayArray[i][j] = grayC;
}// inner for*/
}
return GrayArray;
}
void getGrayImageArray (int** gArray)
{
this->GrayArray = gArray;
}
bool** GetBinaryArray( int level )
{
BArray = new bool * [xsize];
for (int i = 0; i < xsize; i++ )
{
BArray[i] = new bool[ysize];
}
binary = new int * [xsize];
for (int i = 0; i < xsize; i++ )
{
binary[i] = new int[ysize];
}
fp=fopen("C:\\binary.txt","w");
int grayC;
for ( int xVal = 0; xVal < xsize; xVal++ )
{
for( int yVal = 0; yVal < ysize; yVal++ )
{
grayC = GrayArray[xVal][yVal];
if ( grayC >= level )
{
BArray[xVal][yVal] = true;
binary[xVal][yVal] = 1;
fprintf(fp,"%d",binary[xVal][yVal]);
}
else
{
BArray[xVal][yVal] = false;
binary[xVal][yVal] = 0;
fprintf(fp,"%d",binary[xVal][yVal]);
}
}// inner for*/
}
fclose(fp);
return BArray;
}
};
When I press Retry, then breakpoint showing this line.
fprintf(fp,"%d",binary[xVal][yVal]);
If I remove these lines then showing breakpoint in main program.
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Breakpoint showing in return 0 this line.

Actually this is a well known problem. I have already solved this topics. In my code I had created text files, docx files and images in C drives. But there was no permission for accessing C drive in my computer.
Then I had solved by following this steps:
If you can access cmd, you can reset the security settings in
Vista/Windows 7 with the following command: "secedit /configure /cfg
%windir%\inf\defltbase.inf /db defltbase.sdb /verbose" (no quotes.)
To see what this command does, go here: How do I restore security
settings to the default settings?
NOTE: If you can't access cmd when logged in, use this guide
System Recovery Options. You can get to the command line when you
access the System Recovery Options screen.
This command seems to give the ownership issue a kick up the
backside, even though it seems nothing has changed. Go to Explorer,
right click on C: and go to Properties.
Go to the Security tab and then Advanced.
Go to the Owner tab. Now you should be able to click Edit.
If you don't have Administrators in the list under where it says
"Change owner to:" then go to "Other users or groups". If you do, go
straight to step 7.
On Others users or groups type in "Administrators" (no quotes) in
the bottom box. Click Check Name and then OK.
Click Administrators and then OK. You've now given yourself
ownership of C:! (As long as your account is an Administrator, that
is.)
Click OK on the "Advanced Security Settings..." window to get back
to the Properties window. You should now have a list of the
Permissions and so on where before you only had something about how
you couldn't view permissions. Progress, eh?
You may need to add in the Adminstrators group to edit their
permissions. To do this, click "Edit" and then "Add" and type
"Administrators" (no quotes) in the bottom box. Then hit Check Name
and then OK.
Click Administrators in the list and tick the box in the Allow
column next to "Full control".
Click Apply, you'll likely get a bunch of error messages about how
this can't be applied to some files and folders. Just OK through
them all. Once done, you should have access to your C: drive once
more!
Source Link

Related

Why does my pam work for sudo and not for ssh?

I have written a PAM module that displays a QR-code when we do the $ sudo su command. The PAM only displays the QR code, no verification is made and no password is asked.
I tried to use this PAM with ssh but nothing is displayed on the screen. Does anybody know why ?
Now I have half of a qr code...
This function is drawing the qr code on the terminal :
void output_ansi(FILE * file, const struct qr_bitmap * bmp)
{
const char * out[2] = {
" ",
"\033[7m \033[0m",
};
unsigned char * line;
size_t x, y;
line = bmp->bits;
for (y = 0; y < bmp->height; ++y) {
fprintf(file, "%d\n",y );
for (x = 0; x < bmp->width; ++x) {
int mask = 1 << (x % CHAR_BIT);
int byte = line[x / CHAR_BIT];
fprintf(file, "%s", out[!!(byte & mask)]);
}
fputc('\n', file);
line += bmp->stride;
}
}
But by displaying the value of y in the for loop, I noticed that the first 9 lines are not printed... does anybody know what is the problem ?

in windows 10, redirect port monitor (redmon), run as user doesn't work

I have a redirected printer port that use redmon (redirect port monitor) with a postscript printer driver to convert postscript to pdf and apply some other effects like watermarks, overlays, etc.
In win 7 all work fine but in windows 10 the process run under system user account.
In the configuration window of the printer port there is a flag called "Run as user" and in win7, checking this flag let the job running under the user account.
In Windows 10 it seems not working.
Any suggestion will be very appreciated.
Thank you.
Roy
I had a similar problem. I needed the user that printed the document to select the type of document and a patient ID. Then print the document to our EHR system as a PDF. Works in Windows 7 when "Run as User" is checked, but not on Windows 10. Redmon always runs the program as "SYSTEM". So I added a bit to the beginning of the program to check the user name. If it is "SYSTEM" the program looks for the an interactive user on the system by finding an instance of explorer.exe. If more than one interactive user is logged onto the system this will fail. Not a problem for my task. The program then starts another instance of itself running as the same user as explorer.exe, passing the same command line. A pipe is used so that stdin from the first instance can be piped to stdin on the second instance. Another limitation is that on a 64 bit OS, a 64 bit version of the program must be used. Otherwise explorer.exe may not be found.
The following code is what I placed at the beginning of my program. Don't be fooled by the program starting at main(). I am using a GUII toolkit that has WinMain() in it and then calls main(). I have only tested the code on ASCII programs. I tried to use the ASCII version of calls so that it would work with non-ASCII programs, but I am not sure I got all of them.
The LogInfoSys("Hello World"); function just writes to a log file.
Good luck.
#include <Windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <time.h>
#include <direct.h>
#include <process.h>
#include <sqlext.h>
#include <Psapi.h>
#include <tlhelp32.h>
int main(int argc, char *argv[])
{
int error;
char msg[1024];
DWORD *processIDs;
int processCount;
HANDLE hProcess = NULL;
HANDLE hToken;
char userName[64];
char progName[1024];
int i, j;
char nameMe[256];
char domainMe[256];
PTOKEN_USER ptuMe = NULL;
PROCESS_INFORMATION procInfo;
STARTUPINFO startUpInfo;
HMODULE *hMod;
DWORD cbNeeded;
SECURITY_ATTRIBUTES saAttr;
HANDLE hChildStd_IN_Rd = NULL;
HANDLE hChildStd_IN_Wr = NULL;
i = 64; // Get user name, if it is "SYSTEM" redirect input to output to a new instance of the program
GetUserNameA(userName, &i);
if (_stricmp(userName, "system") == 0)
{
LogInfoSys("Running as SYSTEM");
processIDs = (DWORD *)calloc(16384, sizeof(DWORD)); // Look for explorer.exe running. If found that should be the user we want to run as.
EnumProcesses(processIDs, sizeof(DWORD) * 16384, &i); // If there is more than one that is OK as long as they are both being run by the same
processCount = i / sizeof(DWORD); // user. If more than one user is logged on, this will be a problem.
hMod = (HMODULE *)calloc(4096, sizeof(HMODULE));
hProcess = NULL;
for (i = 0; (i < processCount) && (hProcess == NULL); i++)
{
if (processIDs[i] == 11276)
Sleep(0);
if (processIDs[i] != 0)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processIDs[i]);
if (hProcess != NULL)
{
cbNeeded = 0;
error = EnumProcessModules(hProcess, hMod, sizeof(HMODULE) * 4096, &cbNeeded);
if (error == 0)
{
error = GetLastError();
Sleep(0);
}
progName[0] = 0;
error = GetModuleBaseNameA(hProcess, hMod[0], progName, 1024);
if (error == 0)
{
error = GetLastError();
Sleep(0);
}
if (_stricmp(progName, "explorer.exe") != 0)
{
CloseHandle(hProcess);
hProcess = NULL;
}
else
{
LogInfoSys("Found explorer.exe");
}
}
}
}
LogInfoSys("After looking for processes.");
nameMe[0] = domainMe[0] = 0;
if (hProcess != NULL)
{
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&hChildStd_IN_Rd, &hChildStd_IN_Wr, &saAttr, 0)) // Create a pipe for the child process's STDIN.
LogInfoSys("Stdin CreatePipe error");
if (!SetHandleInformation(hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0)) // Ensure the write handle to the pipe for STDIN is not inherited.
LogInfoSys("Stdin SetHandleInformation errir");
if (OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken) != 0)
{
GetStartupInfo(&startUpInfo);
startUpInfo.cb = sizeof(STARTUPINFO);
startUpInfo.lpReserved = NULL;
startUpInfo.lpDesktop = NULL;
startUpInfo.lpTitle = NULL;
startUpInfo.dwX = startUpInfo.dwY = 0;
startUpInfo.dwXSize = 0;
startUpInfo.dwYSize = 0;
startUpInfo.dwXCountChars = 0;
startUpInfo.dwYCountChars = 0;
startUpInfo.dwFillAttribute = 0;
startUpInfo.dwFlags |= STARTF_USESTDHANDLES;
startUpInfo.wShowWindow = 0;
startUpInfo.cbReserved2 = 0;
startUpInfo.lpReserved = NULL;
startUpInfo.hStdInput = hChildStd_IN_Rd;
startUpInfo.hStdOutput = NULL;
startUpInfo.hStdError = NULL;
GetModuleFileName(NULL, progName, 1024);
i = CreateProcessAsUserA(hToken, progName, GetCommandLine(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startUpInfo, &procInfo);
if (i == 0)
{
i = GetLastError();
}
do
{
i = (int)fread(msg, 1, 1024, stdin);
if (i > 0)
WriteFile(hChildStd_IN_Wr, msg, i, &j, NULL);
} while (i > 0);
}
}
LogInfoSys("End of running as SYSTEM.");
exit(0);
}
/**********************************************************************************************************
*
* End of running as SYSTEM and start of running as the user that printed the document (I hope).
*
**********************************************************************************************************/
exit(0);
}

Sprite Smooth movement and facing position according to movement

i'm trying to make this interaction with keyboard for movement using some sprites and i got stuck with two situations.
1) The character movement is not going acording to the animation itself (it only begin moving after one second or so while it's already being animated). What i really want it to do is, to move without a "initial acceleration feeling" that i get because of this problem
2) I can't think of a way to make the character face the position it should be facing when the key is released. I'll post the code here, but since it need images to work correctly and is not so small i made a skecth available at this link if you want to check it out: https://www.openprocessing.org/sketch/439572
PImage[] reverseRun = new PImage [16];
PImage[] zeroArray = new PImage [16];
void setup(){
size(800,600);
//Right Facing
for(int i = 0; i < zeroArray.length; i++){
zeroArray[i] = loadImage (i + ".png");
zeroArray[i].resize(155,155);
}
//Left Facing
for( int z = 0; z < reverseRun.length; z++){
reverseRun[z] = loadImage ( "mirror" + z + ".png");
reverseRun[z].resize(155,155);
}
}
void draw(){
frameRate(15);
background(255);
imageMode(CENTER);
if(x > width+10){
x = 0;
} else if (x < - 10){
x = width;}
if (i >= zeroArray.length){
i = 3;} //looping to generate constant motiion
if ( z >= reverseRun.length){
z = 3;} //looping to generate constant motiion
if (isRight) {
image(zeroArray[i], x, 300);
i++;
} //going through the images at the array
else if (isLeft) {
image(reverseRun[z],x,300);
z++;
} going through the images at the array
else if(!isRight){
image(zeroArray[i], x, 300);
i = 0; } //"stoped" sprite
}
}
//movement
float x = 300;
float y = 300;
float i = 0;
float z = 0;
float speed = 25;
boolean isLeft, isRight, isUp, isDown;
void keyPressed() {
setMove(keyCode, true);
if (isLeft ){
x -= speed;
}
if(isRight){
x += speed;
}
}
void keyReleased() {
setMove(keyCode, false);
}
boolean setMove(int k, boolean b) {
switch (k) {
case UP:
return isUp = b;
case DOWN:
return isDown = b;
case LEFT:
return isLeft = b;
case RIGHT:
return isRight = b;
default:
return b; }
}
The movement problem is caused by your operating system setting a delay between key presses. Try this out by going to a text editor and holding down a key. You'll notice that a character shows up immediately, followed by a delay, followed by the character repeating until you release the key.
That delay is also happening between calls to the keyPressed() function. And since you're moving the character (by modifying the x variable) inside the keyPressed() function, you're seeing a delay in the movement.
The solution to this problem is to check which key is pressed instead of relying solely on the keyPressed() function. You could use the keyCode variable inside the draw() function, or you could keep track of which key is pressed using a set of boolean variables.
Note that you're actually already doing that with the isLeft and isRight variables. But you're only checking them in the keyPressed() function, which defeats the purpose of them because of the problem I outlined above.
In other words, move this block from the keyPressed() function so it's inside the draw() function instead:
if (isLeft ){
x -= speed;
}
if(isRight){
x += speed;
}
As for knowing which way to face when the character is not moving, you could do that using another boolean value that keeps track of which direction you're facing.
Side note: you should really try to properly indent your code, as right now it's pretty hard to read.
Shameless self-promotion: I wrote a tutorial on user input in Processing available here.

Saving randomly generated passwords to a text file in order to display them later

I'm currently in a traineeship and I currently have to softwares I'm working on. The most important was requested yesterday and I'm stucked on the failure of its main feature: saving passwords.
The application is developped in C++\CLR using Visual Studio 2013 (Couldn't install MFC libraries somehow, installation kept failing and crashing even after multiple reboots.) and aims to generate a password from a seed provided by the user. The generated password will be save onto a .txt file. If the seed has already been used then the previously generated password will show up.
Unfortunately I can't save the password and seed to the file, though I can write the seed if I don't get to the end of the document. I went for the "if line is empty then write this to the document" but it doesn't work and I can't find out why. However I can read the passwords without any problem.
Here's the interresting part of the source:
int seed;
char genRandom() {
static const char letters[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(letters) - 1;
return letters[rand() % stringLength];
}
System::Void OK_Click(System::Object^ sender, System::EventArgs^ e) {
fstream passwords;
if (!(passwords.is_open())) {
passwords.open("passwords.txt", ios::in | ios::out);
}
string gen = msclr::interop::marshal_as<std::string>(GENERATOR->Text), line, genf = gen;
bool empty_line_found = false;
while (empty_line_found == false) {
getline(passwords, line);
if (gen == line) {
getline(passwords, line);
PASSWORD->Text = msclr::interop::marshal_as<System::String^>(line);
break;
}
if (line.empty()) {
for (unsigned int i = 0; i < gen.length(); i++) {
seed += gen[i];
}
srand(seed);
string pass;
for (int i = 0; i < 10; ++i) {
pass += genRandom();
}
passwords << pass << endl << gen << "";
PASSWORD->Text = msclr::interop::marshal_as<System::String^>(pass);
empty_line_found = true;
}
}
}
I've also tried replacing ios::in by ios::app and it doesn't work. And yes I have included fstream, iostream, etc.
Thanks in advance!
[EDIT]
Just solved this problem. Thanks Rook for putting me on the right way. It feels like a silly way to do it, but I've closed the file and re-openned it using ios::app to write at the end of it. I also solved a stupid mistake resulting in writing the password before the seed and not inserting a final line so the main loop can still work. Here's the code in case someone ends up with the same problem:
int seed;
char genRandom() {
static const char letters[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(letters) - 1;
return letters[rand() % stringLength];
}
System::Void OK_Click(System::Object^ sender, System::EventArgs^ e) {
fstream passwords;
if (!(passwords.is_open())) {
passwords.open("passwords.txt", ios::in | ios::out);
}
string gen = msclr::interop::marshal_as<std::string>(GENERATOR->Text), line, genf = gen;
bool empty_line_found = false;
while (empty_line_found == false) {
getline(passwords, line);
if (gen == line) {
getline(passwords, line);
PASSWORD->Text = msclr::interop::marshal_as<System::String^>(line);
break;
}
if (line.empty()) {
passwords.close();
passwords.open("passwords.txt", ios::app);
for (unsigned int i = 0; i < gen.length(); i++) {
seed += gen[i];
}
srand(seed);
string pass;
for (int i = 0; i < 10; ++i) {
pass += genRandom();
}
passwords << gen << endl << pass << endl << "";
PASSWORD->Text = msclr::interop::marshal_as<System::String^>(pass);
empty_line_found = true;
}
}
passwords.close();
}
So, here's an interesting thing:
passwords << pass << endl << gen << "";
You're not ending that with a newline. This means the very end of your file could be missing a newline too. This has an interesting effect when you do this on the final line:
getline(passwords, line);
getline will read until it sees a line ending, or an EOF. If there's no newline, it'll hit that EOF and then set the EOF bit on the stream. That means the next time you try to do this:
passwords << pass << endl << gen << "";
the stream will refuse to write anything, because it is in an eof state. There are various things you can do here, but the simplest would be to do passwords.clear() to remove any error flags like eof. I'd be very cautious about accidentally clearing genuine error flags though; read the docs for fstream carefully.
I also reiterate my comment about C++/CLR being a glue language, and not a great language for general purpose development, which would be best done using C++ or a .net language, such as C#. If you're absolutely wedded to C++/CLR for some reason, you may as well make use of the extensive .net library so you don't have to pointlessly martial managed types back and forth. See System::IO::FileStream for example.

How to duplicate symbols and the coding associated with them

I have trouble with copying symbols, to do the same thing, in this case I need a symbol to restrict movement, to do this I created a variable for movement for each key press,
var velocity: int = 5;
var left: int = -5;
var up: int = 5;
var down: int = -5;
it worked for the first set of symbols, but when I copied the symbols and renamed them it only worked on the new symbol.
here is the coding example for the hit test I use, which works on single symbols
if (head_mc.hitTestObject(wallleft_mc)) {
left = 0;
trace("Collision detected!");
} else {
trace("No collision.");
left = -5;
}
if (head_mc.hitTestObject(wallleft2_mc)) {
left = 0;
trace("Collision detected!");
} else {
trace("No collision.");
left = -5;
}
wallleft2_mc is a copy of wallleft_mc, which I copied via pressing alt and dragging to the new location.
when I run the program, no errors appear, but the movement restriction code in the hit test codes only works on one of the symbols, not both.
how would I make it work both?
without creating new variables, which I tried to do,
thanks,
really appreciate the help, thanks