|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
2 Errors:
a) Lambda does not not with static var, so I must to work wwith bind
b) I try to invoke functions of class from DLL, saved in unordered_map object and fall.If to invoke functions of class not from DLL it is work properly.
How can this problem be solved?
file UnorderedMapFunctions.cpp
<pre lang="C++">#include <iostream>
#include <unordered_map>
#include <functional>
#include <windows.h>
#include "..\\Geometry\\Geometry.h"
using namespace std;
namespace NS
{
class Math
{
public:
int Sum(int x, int y) { return x + y; }
int Sub(int x, int y) { return x - y; }
int Mul(int x, int y) { return x * y; }
int Div(int x, int y) { return x / y; }
};
}
using namespace NS;
int main()
{
unordered_map<string, function<int(int, int)>>* mydata = new unordered_map<string, function<int(int, int)>>;
Math* m = new Math;
(*mydata)["sum"] = [m](int x, int y) { return m->Sum(x, y); };
(*mydata)["sub"] = [m](int x, int y) { return m->Sub(x, y); };
(*mydata)["mul"] = [m](int x, int y) { return m->Mul(x, y); };
(*mydata)["div"] = [m](int x, int y) { return m->Div(x, y); };
string fullname_dll = "Geometry";
HINSTANCE hInst = LoadLibraryA(fullname_dll.c_str());
if (hInst == nullptr)
{
cout << "Error: [FuncImport] wrong name " << fullname_dll.c_str() << endl;
return false;
}
typedef void (CALLBACK* CreateInstanceFunc)(unordered_map<string, function<int(int, int)>>* mydata);
string CreateFuncName = "CreateInstance";
CreateInstanceFunc CreateInstance = (CreateInstanceFunc)GetProcAddress(hInst, CreateFuncName.c_str());
if (CreateInstance == nullptr)
{
cout << "Error: wrong name " << fullname_dll << endl;
FreeLibrary(hInst);
return false;
}
CreateInstance(mydata);
cout << "Imported " << fullname_dll.c_str();
FreeLibrary(hInst);
for (const auto& [k, v] : *mydata)
std::cout << "Key: " << k << " Value: " << v(3, 5) << std::endl;
auto it = mydata->find("circle");
if (it != mydata->end())
cout << "\nKey: " << it->first << " Value: " << it->second(4, 2) << std::endl;
else
cout << "Error\n";
delete m;
delete mydata;
return 0;
} //=============================================================
2 Dll files: Geometry.h, Geometry.cpp
file Geometry.h
#pragma once
#include <iostream>
#include <unordered_map>
#include <functional>
#include <windows.h>
#ifdef GEOMETRY_EXPORTS
#define GEOMETRY_API __declspec(dllexport)
#else
#define GEOMETRY_API __declspec(dllimport)
#endif
using namespace std;
namespace NS
{
class GEOMETRY_API Geometry
{
public:
Geometry();
int Circle(int x, int y);
int Rectangle(int x, int y);
};
extern "C" void GEOMETRY_API CreateInstance(unordered_map<string, function<int(int, int)>>* mydata);
extern "C" void GEOMETRY_API Cleanup();
}
file Geometry.cpp
#include "pch.h"
#include "Geometry.h"
namespace NS
{
Geometry* geometryInstance;
void CreateInstance(unordered_map<string, function<int(int, int)>>* mydata)
{
geometryInstance = new Geometry;
(*mydata)["circle"] = bind(&Geometry::Circle, geometryInstance, placeholders::_1, placeholders::_2);
(*mydata)["rectangle"] = bind(&Geometry::Rectangle, geometryInstance, placeholders::_1, placeholders::_2);
}
Geometry::Geometry() {}
int Geometry::Circle(int x, int y) { return 3.14 * x * x; }
int Geometry::Rectangle(int x, int y) { return x * y; }
void Cleanup()
{
delete geometryInstance;
geometryInstance = nullptr;
}
}
|
|
|
|
|
I find your code somewhat difficult top understand. However as far as far as I can guess, the problem occurs in the following lines:
FreeLibrary(hInst);
for (const auto& [k, v] : *mydata)
std::cout << "Key: " << k << " Value: " << v(3, 5) << std::endl;
You call FreeLibrary and then (I think) try to invoke the functions that are served by that library.
|
|
|
|
|
My very stupid mistake! You right Richard, thank you very much. I convert my project(GitHub - okogosov/PPL: Parenthesis Programming Language (PPL)[^]) from C# to C++ and in C# I do not use FreeLibrary. But I use AI MONICA a little for convertation and call "FreeLibrary" will be generated and added by AI. I express my gratitude to you (and MONICA also) and to all my colleaques for help with the project that I am working alone.
|
|
|
|
|
You are welcome. And remember the key word in AI is "artificial".
|
|
|
|
|
Exactly. Apropo - your profile is very similar to mine - also retired, started o Mainframe (Asm, Cobol, PL/1) and continue to learn new soft.
|
|
|
|
|
Yes, parallel processing the two of us.
|
|
|
|
|
hi,
I am not sure what is missing.
I created 16 bit grayscale buffer and pass it to glDrawPixels(..) , then in mouse function callback I try to read the first pixel with glReadPixels(0,0,1,1,GL_LUMINANCE ,GL_UNSIGNED_SHORT,pixUnSigShort) and is wrong. Tried also GL_LUMINANCE16.
|
|
|
|
|
etechX2 wrote: ... and is wrong.
Define "wrong".
|
|
|
|
|
16 bit pixel value bytes read from glReadPixels(0,0,,,) are like X1 X1 X2 X2 ... etc. They do not match the raw image pixels. The image is brighter liked a image that has a filter applied to it. I am not sure if I am reading from framebuffer. I sed GL_LUMINANCE with GL_UNSIGNED_SHORT. It is a grayscale image.
modified yesterday.
|
|
|
|
|
Prepare the following strings in advance as an array. Be sure to write everything in full-width characters.
"The difference between being 18 and 81. 18 years old is the one who drowns in love, 81 years old is the one who drowns in the bath. 18 years old is the one who runs down the road, and vice versa.
The person running is 81 years old. An 18-year-old has a fragile heart, and an 81-year-old has a fragile bone. I'm 18 years old and my heart can't stop pounding.
He is 81 years old and can't stop the plane. An 18-year-old can choke on love, and an 81-year-old can choke on rice cakes. I'm concerned about the deviation value
I am 18 years old, and I am 81 years old and concerned about my blood pressure and blood sugar levels. An 18-year-old who doesn't know anything yet, an 81-year-old who doesn't remember anything anymore.
An 18-year-old who is looking for himself, and an 81-year-old who is looking for everyone else. "
- Then have the user enter a search string. Search characters can be up to 10 characters.
・Then, have the user enter a replacement string. Replacement characters can be up to 10 characters.
- Perform a prefix match search on the above string and replace all hit strings.
- After replacing, output the result to the screen. If there are no conversion candidates, "Nothing to convert" is displayed.(if the searched string is in more than 1 place on the original string, the replacement will replace all of it)
Community Verified icon
|
|
|
|
|
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Just doing a copy'n'paste of your assignment will get you nowhere.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thanks,I got to the point of searching input and limiting it to 10 characters but I dont know how to replace that searched words.
modified 5 days ago.
|
|
|
|
|
And? What have you tried?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
#include <stdio.h>
#include <string.h>
#define MAX_STRINGS 3
#define MAX_LENGTH 512
void searchAndReplace(char text[][MAX_LENGTH], int numStrings, const char* searchStr, const char* replaceStr) {
int replaced = 0;
for (int i = 0; i < numStrings; ++i) {
char buffer[MAX_LENGTH];
char* pos;
size_t searchLen = strlen(searchStr);
size_t replaceLen = strlen(replaceStr);
strcpy_s(buffer, text[i]);
while ((pos = strstr(buffer, searchStr)) != NULL) {
if (!replaced) {
printf("%s\n", text[i]);
replaced = 1;
}
size_t len = strlen(pos + searchLen);
memmove(pos + replaceLen, pos + searchLen, len + 1);
memcpy(pos, replaceStr, replaceLen);
}
if (replaced) {
printf("%s\n", buffer);
replaced = 0; }
}
}
int main() {
char strings[MAX_STRINGS][MAX_LENGTH] = {
"18歳と81歳の違い。18歳は恋に溺れる人で、81歳はお風呂に溺れる人。18歳は道を走り、逆もまた然り。81歳の人が走っている。18歳は心がもろく、81歳は骨がもろい。私は18歳で心臓が止まらない。",
"81歳の彼は飛行機を止められない。18歳は恋に窒息することができ、81歳は餅に窒息することができる。偏差値が気になる。私は18歳で、81歳で血圧と血糖値を気にしている。まだ何も知らない18歳、もう何も覚えていない81歳。",
"自分を探している18歳と、みんなを探している81歳。"
};
printf("Original strings:\n");
for (int i = 0; i < MAX_STRINGS; ++i) {
printf("%s\n", strings[i]);
}
char searchStr[11], replaceStr[11];
printf("Enter search string (up to 10 characters): ");
fgets(searchStr, sizeof(searchStr), stdin);
searchStr[strcspn(searchStr, "\n")] = '\0'; printf("Enter replacement string (up to 10 characters): ");
fgets(replaceStr, sizeof(replaceStr), stdin);
replaceStr[strcspn(replaceStr, "\n")] = '\0';
if (strlen(searchStr) > 10 || strlen(replaceStr) > 10) {
fprintf(stderr, "Search and replacement strings must be up to 10 characters long.\n");
return 1;
}
int found = 0;
for (int i = 0; i < MAX_STRINGS; ++i) {
if (strstr(strings[i], searchStr) != NULL) {
found = 1;
searchAndReplace(strings, MAX_STRINGS, searchStr, replaceStr);
}
}
if (!found) {
printf("Nothing is changed.\n");
}
return 0;
}
this is best one I tried and it does not replace the words on the original string.
[edit]
OriginalGriff: code block added
[/edit]
modified 5 days ago.
|
|
|
|
|
Why not? What did the debugger show you was happening?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
the debugger let me input my search string and not letting me enter my replacement string. I made it so that 10 letters can be enter into it but it stop working when I put letters over 3. Are there any chance the program is mistaking one japanese word into 3 letters?
|
|
|
|
|
Assuming that your Japanese is in Unicode (Hiragana / Katakana) then it'll usually be 2 bytes per character, but it is possible to use three byte Unicode (since the possible range is 21 bits, meaning 3 bytes)
What exactly do you mean "not letting me enter my replacement string." I'm pretty sure it didn't try to smack your wrist and tell you off but what exactly did happen? How did you check?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
char on it's own is 1 byte - for Unicode you probably need to use the uchar.h header and its' types, but I've never needed them so I can't help you that much. You might want to check your course notes and Google before going any further.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Member 16311074 wrote: ...not letting me enter my replacement string. Try changing the size of searchStr and replaceStr to something too large (but still only enter 10 characters). When you make them just large enough and you enter in that many characters, fgets() leaves the \n in the keyboard buffer and the second call to fgets() see it and exits right away.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
First run:
~~~~~~~~~~~~~~~~
Original strings:
18歳と81歳の違い。18歳は恋に溺れる人で、81歳はお風呂に溺れる人。18歳は道を走り、逆もまた然り。81歳の人が走っている。18歳は心がもろく、81歳は骨がもろい。私は18歳で心臓が止まらない。
81歳の彼は飛行機を止められない。18歳は恋に窒息することができ、81歳は餅に窒息することができる。偏差値が気になる。私は18歳で、81歳で血圧と血糖値を気にしている。まだ何も知らない18歳、もう何も覚えていない81歳。
自分を探している18歳と、みんなを探している81歳。
Enter search string (up to 10 characters): 2
Enter replacement string (up to 10 characters): #
Nothing is changed.
Second run:
~~~~~~~~~~~
Original strings:
18歳と81歳の違い。18歳は恋に溺れる人で、81歳はお風呂に溺れる人。18歳は道を走り、逆もまた然り。81歳の人が走っている。18歳は心がもろく、81歳は骨がもろい。私は18歳で心臓が止まらない。
81歳の彼は飛行機を止められない。18歳は恋に窒息することができ、81歳は餅に窒息することができる。偏差値が気になる。私は18歳で、81歳で血圧と血糖値を気にしている。まだ何も知らない18歳、もう何も覚えていない81歳。
自分を探している18歳と、みんなを探している81歳。
Enter search string (up to 10 characters): πéèπ
Enter replacement string (up to 10 characters): ----
18歳と81歳の違い。18歳は恋に溺れる人で、81歳はお風呂に溺れる人。18歳は道を走り、逆もまた然り。81歳の人が走っている。18歳は心がもろく、81歳は骨がもろい。私は18歳で心臓が止まらない。
∩╝æ∩╝ÿµ¡│πü¿∩╝ÿ∩╝浡│πü«ΘüòπüäπÇé∩╝æ∩╝ÿµ¡│πü»µüïπü½µ║║πéîπéïΣ║║πüºπÇü∩╝ÿ∩╝浡│πü»πüèΘó¿σæéπü½µ║║πéîπéïΣ║║πÇé∩╝æ∩╝ÿµ¡│πü»ΘüôπéÆΦ╡░----ÇüΘÇåπééπü╛πüƒτä╢----Çé∩╝ÿ∩╝浡│πü«Σ║║πüîΦ╡░πüúπüªπüäπéïπÇé∩╝æ∩╝ÿµ¡│πü»σ┐âπüîπééπéìπüÅπÇü∩╝ÿ∩╝浡│πü»Θ¬¿πüîπééπéìπüäπÇéτºüπü»∩╝æ∩╝ÿµ¡│πüºσ┐âΦçôπüóπü╛πéëπü¬πüäπÇé
Seems to be running as expected here.
|
|
|
|
|
Member 16311074 wrote: replaced = 0; // Reset for the next string Since replaced is a local variable (and searchAndReplace() is not static ), this statement does nothing useful. This has nothing to do with your overall issue, though.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Does anyone know the use of QueryChangesVirtualDisk ?
I have call the function successfully.
But how to use the QUERY_CHANGES_VIRTUAL_DISK_RANGE?
|
|
|
|
|
|