Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
So what I'm trying to do is simple; I want to write a function into the memory of another process and execute it. What I've done is gotten the size of the function and just used WriteProcessMemory to do this. I have successfully created a thread to run this function, confirmed using cheat engine's debugging features.
The function looks like so:
inline void __cdecl Test( )
{ }
Looks pretty simple. It shouldn't rely on anything that needs to be relocated, so it should work just fine. It is inline because I defined it in a header, if that is relevant. Although this function does NOTHING, this is what is happening in cheat engine:
It's odd that it's copying a string, but more so that it's calling a function? Since this random function call is happening, the program crashes because the address isn't relocated to match where functions are in the new process. So, my question is: why in the world is it calling a function and how can I stop this from happening?
So basically, debug mode was the cause for this issue and does not occur in release.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What it looks like is happening is that memory is being used to store a function pointer inside every instance of my structs for every friend function declared inside of them. I had trouble finding info on this and needed confirmation before making major code changes.
The struct in question has about 10 million instances, so this becomes a significant amount of memory consumption.
Do friend functions add size to a C++ struct/class?
The language doesn't specify exhaustively what affect the size of a class. But in practice no, there is generally no reason why a friend function would need to affect the size of a class.
The friend functions were not adding size to the struct.
If you must know the source of my stupidity so it is not repeated, I had an array of char pointers instead of an array of chars by mistake:
char* OwnerName[20];
instead of
char OwnerName[20];
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm writing a little project in C++ using SFML, and I run into a problem. I want to draw a few lines and I would like to change the amount of them when running my program (and I want maximum of like 50 lines). So I figured, I would use a std::vector, but I need to call non default constructor on every line object and I can't find an easier way than doing it in a loop (I don't even know if I should do it anyway). I tried this:
std::vector<sf::VertexArray> lines(50, sf::VertexArray(2, sf::Lines));
but it doesn't work. (I might be wrong, it was a thing until C++ 11?).
And I ask how to do something like this (also when resizing the vector) or maybe should I find another way of storing these lines? I'm using sf::VertexArray, because I really need a line described as 2 points, and not as a rectangle.
According to documentation:
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1VertexArray.php#a4bb1c29a0e3354a035075899d84f02f9
constructor for VertexArray is as follows:
sf::VertexArray::VertexArray ( PrimitiveType type,
std::size_t vertexCount = 0
)
so the first argument should be of PrimitiveType and the second is the count. You have it the other way around. So change:
std::vector<sf::VertexArray> lines(50, sf::VertexArray(2, sf::Lines));
to:
std::vector<sf::VertexArray> lines(50, sf::VertexArray(sf::Lines, 2));
Otherwise your code looks fine.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
This is a simple 2 line question that I just don't understand.
I just created an array with 3 members, and immediately afterwards, the size is reported as 6. It was working before, but all of sudden changed. I tried cleaning my project.
This is using Visual Studio 2015
std::string detectionMethods[3] = { "SQUARE", "CIRCLE", "CIRCLE-SSV" };
int k_size = detectionMethods->length();
Thanks,
Source code and debug screenshot
There's no such thing as a member function of a raw array.
The sub-expression detectionMethods refers to the raw array and decays to a pointer to the first item. The rest, ->length(), calls a member function of the first item.
One easy way to avoid these problems is to use std::vector instead of a raw array. Your book should be recommending that.
The size of the first string is been returned.
The reason is that a variable which is an array, decays to a pointer to the first element.
So calling detectionMethods->length() is the same as calling detectionMethods[0].length()
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I try to run this code, but I encounter the error as shown above . My first assumption is the linker file is incorrect. If my linker file is incorrect, then what should I change for the linker file?
My second assumption is I set a wrong path to the linker file. Currently, I set my path to C:\Apps\MinGW\bin. If my path is wrong, then what should I set my path to?
Not sure where you got the idea that the entry point should be called run. It should be called main, just rename it:
int main ()
{
....
}
That particular error message is a bit misleading to the untrained eye (explaining it goes further down the rabbit hole than I'd like to go) but that's essentially what that one means in this context.
I think, main is required for every CPP program.
Whenever you start compiling your program, the complier will find this function first and of course your program doesn't contain this.
So, try changing the function from run to main
Hope it works!
Change
int run()
{
}
to
int main()
{
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
edit: Sorry about that, I put in the wrong vector. And this is the non working code. The line 'stage_4.resize(20, vector(20, 0));' is giving me the error. 'stage_4.resize(20); works, but I couldn't get it to compile by adjusting both dimensions. Also, I forgot to mention I'm using Code::Blocks 13.12 and Mingw32-gcc.
I'm relatively new to c++ and have basically learned by reading tutorials on the internet so there are some pretty big gaps in my understanding of it. I've been trying to write a program using more classes to make things more streamlined and just started looking into using vectors. However, I've hit a bit of a snag in the combination of the two. I've created a class, and made a vector within it. It all compiles fine until I try to resize the vector as a 2 dimensional array within a function of the class. Here's the relevant code.
class stage{
public:
std::vector<int> stage_4;
int setup(int a){
switch (a){
case 1:
stage_4.resize(20, vector<int>(20, 0));
break;
}
}
}
When I just do stage_4.resize(20); It compiles no problem. But when I try to change both dimensions of the array, like in this code, it tells me "error: 'vector' was not declared in this scope". I'm not really sure what I'm doing wrong since, as I said, I'm fairly new to c++.
edit: I also tried to do stage_4.resize(20, std::vector(20,0));, but then it tells me "no matching function for call to 'std::vector::resize(int, std::vector)'"
It's std::vector.
vector lives in the std namespace.