|
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
|
|
|
|
|
Hello
i am a total newbie in C++ and i am learning by tryning to modify an existing code which uses displays.
In the original code there are 2 displays showing informations to the user
I want to add a third display do i copied the screen2.cpp and screen2.h and renamed them to screen3.cpp and screen3.h
Inside the screen3 code i replace all mentions of screen2 by screen3
and i added the screen 3 in the screens.cpp script
// User screens
MMIRegisterScreen(SCREENID_1, Screen1Enter, Screen1Create, Screen1Update, Screen1Exit);
MMIRegisterScreen(SCREENID_2, Screen2Enter, Screen2Create, Screen2Update, Screen2Exit);
MMIRegisterScreen(SCREENID_3, Screen3Enter, Screen3Create, Screen3Update, Screen3Exit);
My problem is that when i debug i end up with 4 error messages as the Screen3Enter, Screen3Create , Screen3Update and Screen3Exit are not declared
This is strange as in the screen3.cpp the functions here above are declared the same way they are declared for the other screen i copied from
void Screen3Enter(void)
{
}
void Screen3Create(void)
{
Thanks for your suggestions
modified yesterday.
|
|
|
|
|
No one here can guess what this code is doing, or what it is supposed to do. And trying to learn C++ by modifying someone else's code is not a great idea.
|
|
|
|
|
OK thanks but i have no time to learn from scratch
I have an existing code doing more or less what i expect on the displays and am trying to make it look how i want.
|
|
|
|
|
Carbonkevlar13 wrote: i have no time to learn from scratch Then you are going to need a lot of luck, and will probably get very frustrated. Looking at the few lines of code you did show suggests that it is a Windows GUI application, so that is another subject you will need to learn.
|
|
|
|
|
You have to find where
Screen2Enter, Screen2Create, Screen2Update, Screen2Exit are declared (and where they are defined) and do something similar to what you've already done: make the brand new
Screen3Enter, Screen3Create, Screen3Update, Screen3Exit copying and renaming. Unfortunately the process could go on deeper and deeper.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks
the functions are defined in the script of the screen
I am wondering if they should be declared somewhere else ?
void Screen3Enter(void)
{
}
void Screen3Create(void)
{
// Setup default keys
ScreensSetupDefaultKeys();
|
|
|
|
|
In C++ there is no script. There are, instead, header files (*.h ) and source files (usually *.cpp or *.cc ). You should put the function declarations, e.g.
void Screen3Enter(); in header files, while the function definitions, e.g.
void Screen3Enter()
{
} should be written in source files.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks
i already have these declarations inside screens3.cpp
void Screen3Enter(void)
void Screen3Create(void)
void Screen3Update(void)
void Screen3Exit(void)
when i am inside screens3.cpp there is a "No issues found" message at the bottom of the screen
but when i launch the simulation i have these 4 error messages
C2065 'Screen3Enter' undeclared identifier from the screens.cpp source referring to the following line
MMIRegisterScreen(SCREENID_3, Screen3Enter, Screen3Create, Screen3Update, Screen3Exit);
Thanks for trying to help me
|
|
|
|
|
Put those declarations inside the screens3.h header file. For instance:
#ifndef _SCREENS3_
#define _SCREENS3_
void Screen3Enter(void);
void Screen3Create(void);
void Screen3Update(void);
void Screen3Exit(void);
#endif
then put
#include "screens3.h" in every source file that needs them (e.g. screens.cpp)
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I added #include "screens3.h" in different source files although it was not for the other screens
When i launched the simulator there was an error message saying "cannot open source file screen3.h"
I tried to retype MMIRegisterScreen instead of copying it and when i started to type the first function (screen3Enter) it proposed different functions to me but none for the screen 3 although they qre declared inside the screen3.cpp
I deleted the screen3Enter function and retyped it hoping to see it appear in the list of proposed functions for the MMURefusterScreen but still it was not in the list
|
|
|
|
|
Quote: I added #include "screens3.h" in different source
Quote: there was an error message saying "cannot open source file screen3.h"
can you spot the difference?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
yes
i removed the s from screens3 but no change
finally what i did is modify a fourth screen already programmed with a gauge to benefit from the declarations and it works..
I still do not understand why it did not work with my screen.
Thanks for your help !
|
|
|
|
|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Carbonkevlar13 wrote: I still do not understand why it did not work with my screen. So look carefully at all the other code and compare it line by line with the code that you made.
|
|
|
|
|
As I said earlier, it is impossible to guess without more information. Just showing a couple of random lnes of code gives no real idea of what is missing.
|
|
|
|
|
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,
glReadPixels(0,0,1,1,GL_LUMINANCE ,GL_UNSIGNED_SHORT,pixUnSigShort) , the return pixels values look wrong or unmatched to the raw data.
|
|
|
|
|
etechX2 wrote: ... and is wrong.
Define "wrong".
|
|
|
|
|