|
I've always had difficulty with this, but if memory serves, function pointers in classes are required to be declared static .
[edit]
Memory does not serve.
[/edit]
modified 2-Jun-16 3:16am.
|
|
|
|
|
As per Jochen's answer but I would also add a guard against your forgetting to set the pointer checking it's not NULL. The typecast and advance definition is also unnecessary unless you actually need the type for something, the pointer will be checked for match when you attempt to set it with or without the typecast.
void MyClass::Act(void* pData){
if (m_pfnDoSomething) m_pfnDoSomething(pData);
}
Here is a minimalist function ptr .. no need for forward delaration, typedef or even a name of field. All you need is the * dereference before the function ptr name it knows what you are doing from that and really all it needs is what the function looks like so when you try to set it, that it checks for match.
class MyClass{
void(*MyClass::m_pfnDoSomething)(void*);
void MyClass::Act(void* pData){
if (m_pfnDoSomething) m_pfnDoSomething(pData);
}
};
Finally especially since your in a class I would suggest you don't pass in the void* data pointer but look at other options to typecast or marshal the data in a way that is a little safer.
In vino veritas
modified 4-Jun-16 11:36am.
|
|
|
|
|
How to generate XML file dynamically using C on Linux platform?
|
|
|
|
|
The quick and dirty way it is just matter of printf (and the gcc compiler).
e.g.
#include <stdio.h>
int main(int argc, char * argv[])
{
if (argc != 2) return -1;
printf("<html>\n<head></head>\n<body>\n<p>hello %s, welcome!</p></body></html>", argv[1]);
return 0;
}
|
|
|
|
|
|
Which part(s) are you having trouble with: creating a file, writing data to that file, forming XML, etc?
"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
|
|
|
|
|
Hi,
Well, you have to write the Content!
I have no idea of your compiler environment, but, for starters you need to create or select a folder and a File, where the resulting code will be stored. These files would have a 'htm' or 'html' extension. Most environments I know create the Headers and Footers for a blank Page. You have to write the content of the Page in between. You can inspect your work by opening it in Internet Explorer.
Bram van Kampen
|
|
|
|
|
How to determine file offset of each section using RVA in pe file ?
|
|
|
|
|
Quote from Visual Studio, Microsoft Portable Executable and Common Object File Format Specification RVA Relative virtual address. In an image file, the address of an item after it is loaded into memory, with the base address of the image file subtracted from it. The RVA of an item almost always differs from its position within the file on disk (file pointer).
In an object file, an RVA is less meaningful because memory locations are not assigned. In this case, an RVA would be an address within a section (described later in this table), to which a relocation is later applied during linking. For simplicity, a compiler should just set the first RVA in each section to zero.
|
|
|
|
|
I recommend that you read the many books written by Matt Pietreck on the subject. Even books about Win98 or XP will do. They are Classics, but, explain the lot, in your case in particular, how executable files are mapped to memory. I think that this forms part of the foundation every software engineer should have at his finger tips. Matt wrote several books about spelunking in the bowels of the various windows versions. However User Beware! If you are just interested in how your windows version on your computer does things, read, spelunk, and learn! If you start writing software on the basis of what you learn there, BEWARE! It will work, without doubt on Your computer(where you did the Spelunking!) There is absolutely no guarantee that it will work on any other computer, nor, that it will work after the next windows update! Microsoft provides a large API (Application Program Interface), which Microsoft guarantees to support over the various upgrades. Doing things outside this interface, will sooner or later lead to disaster.
Regards,
Bram van Kampen
|
|
|
|
|
We have a big structure with nearly 300 member variable arrays within it. A Partial of the structure is shown below. We have this structure shared in the memory with another application using CreateFileMapping function. So both the application runs in the same machine sharing the memory. The values of the structure keeps on changing continously based on formulas and calcualtions. Now I need to transfer some of the data values that are changed to another application using sockets continously. If I try to transfer the entire structure of size around 900000bytes continously it gives me problem and hangs.
Please provide me step by step methods to get the values of some of the member variables from the entire structure simply without using any loops to some other structure (only changed values) so that I could transfer this comparitively small structure via sockets to another application and do a similar copy method to get the changed data to the same struture TModDB there in the other application.
struct TModDB
{
float IVKK [600];
char FIL [600];
char FDDD [600];
float FCDCP [600];
float FLH [600];
float FEFTH [600];
float FKL [30][600];
float FPRES [600];
float FTEMP [600];
float FHTR [600];
float FXS [30][600];
float FS1S [600];
float FPDER [600];
float FTDER [600];
float FXDER [30][600];
float FS1DER [600];
float FS5DER [600];
float HEHF [200];
float SS2 [1500];
float SMP [30][1500];
float SK1 [1500];
float SK2 [1500];
float SK3 [1500];
float P1 [250];
float P2 [250];
float P3 [250];
float P4 [250];
float P5 [250];
char LOGIC [100];
float MK3 [100];
char CLOGIC [92];
char CSWT [92];
char LOGV [1500];
char SFEFTH [600];
char SFHOLDUP [600];
char SFTEMP [600];
char SHECDER [200];
char SHEHDER [200];
char SCSPEED [92];
char SFPRES [600];
char SFSDER [30][600];
char SGEFDER [300];
float LMHI [750];
float LMLO [750];
char XVA ;
char FRZE;
char GGGO;
.
.
.
.
char MdelCd;
};
|
|
|
|
|
manoharbalu wrote: Please provide me step by step methods to get the values of some of the member variables Not very easy since we have no idea which items you want copied. In essence you need to define your smaller structure and then use memcpy on the elements you want to copy over.
|
|
|
|
|
Please assume that every alternate member variable data in that structure is to be copied.
|
|
|
|
|
OK, assuming that, what is the problem?
|
|
|
|
|
Define your own protocol to be used with the socket communication. Then send a packet when data has been updated by a calculation. The protocol should be able handle the possible amount of data that is updated by your calculations.
A possible protocol structure may be:
typedef struct
{
int updateType; int firstNdx; int lastNdx; int dataLen; char data[1]; } MyUpdateProtocol;
The updateType may be an enum instead of an <code> int:
enum MyDataMembers
{
IVKK,
FIL,
FDDD,
FCDCP,
};
To create a protocol block calculate the amount of data bytes, allocate memory, cast it, fill it, and send it. Example:
int firstNdx = 0;
int lastNdx = 10;
int dataSize = ((lastNdx - firstNdx) + 1) * sizeof(float);
char *buf = new char[dataSize + sizeof(MyUpdateProtocol) - 1];
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
pProto->updateType = IVKK;
pProto->firstNdx = firstNdx;
pProto->lastNdx = lastNdx;
pProto->dataLen = dataSize;
memcpy(pProto->data, &pModDB->IVKK[firstNdx], dataSize);
sendData(buf, dataSize + sizeof(MyUpdateProtocol) - 1);
delete [] buf;
On the receiving side copy the data according to the protocol header fields:
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
void *dest = NULL;
switch (pProto->updateType)
{
case IVKK : dest = &pModDb->IVKK[pProto->firstNdx]; break;
case FIL : dest = &pModDb->FIL[pProto->firstNdx]; break;
}
memcpy(dest, pProto->data, pProto->dataLen);
|
|
|
|
|
EDIT: LOL hadn't read Jochen's response who did it same way but with some nice protocol sizing. That is pretty nice makes the case statements on the copy enumerate easier. Anyhow you get the idea it isn't a hard task. I will leave the code so you can see what his protocol sizing is simplifying. Did you ever get the network transfer sorted?
Like the people said whats the problem?
You can just do as basic as memcpy I just grabbed your struct and made a zeroed instance and did it to show you.
struct TModDB MyModDB = { 0 };
float DupFXS[30][60];
memcpy(DupFXS, MyModDB.FXS, sizeof(DupFXS));
Really as a commercial thing I would make an enumerator and a single function to copy whatever field I pass the enumerate of or if I can use C++ make it a class or object.
The C enumerate option looks something like follows, your job is to provide a buffer and it's size to the function for the field you are copying
enum DBENUM {
DE_IVKK = 0,
DE_FIL,
DE_FDDD,
DE_FCDCP,
DE_FLH,
};
BOOL DBCopyFunction (enun DBNUM whatToCopy, struct TModDB* TheDB, void* Buf, long SizeOfBuf){
BOOL success = FALSE;
if (TheDb){
switch(whatToCopy){
case DE_IVKK: {
if (sizeof(TheDB->IVKK) <= SizeofBuf) {
memcpy(Buf, TheDB->IVKK, sizeof(TheDB->IVKK));
success = TRUE;
}
}
break;
case DE_FIL: {
if (sizeof(TheDB->FIL) <= SizeofBuf) {
memcpy(Buf, TheDB->FIL, sizeof(TheDB->FIL));
success = TRUE;
}
}
break;
}
}
return (success);
}
There isn't anything complicated that it's just a large complex structure.
In vino veritas
modified 31-May-16 10:28am.
|
|
|
|
|
Thanks a lot for the suggestions.
Let me brief the architecture for your kind understanding
We have 3 applications involved.
1. Model (Runs along with the server and shares the data with Server through Shared memory. Changes the data through formulas and calculations continuously)
2. Server (Updates the data in the shared memory that is changed by the user for recalculation. Gets/Puts the data in shared memory and shares data with model. Also updates client with the updated data from model. Receives user changes from the client.
3. Client (Has number of GUI windows to show the values and receives values from user.)
The Server and the model runs locally and communicates using shared memory. The Client can run either locally or remotely within the network and the communication is using TCP/IP Sockets
I have 2 problems here.
Problem 1:
We dont have hold with the model code. So I cannot detect the value changes from the model.
But both the model and the Server shares the same structure what I have mentioned previously.
So, Is it possible to detect the value changes through shared memory from the Server side?
Problem 2:
As an example if I assume that every alternate member variable array(entire array) is changing, then I have to send 'n' number of times the data through the socket every cycle, where n is the number of member variable arrays in the structure. My concern is the load or performance problem that I had already faced while splitting the data as packets for sending every cycle. I am afraid if the same problem may occur if I send it 'n' number of times.
Please help me and correct me if I am wrong.
|
|
|
|
|
Hi,
You try to detect whether an update has taken place from a remote station.
I take it that you are writing an Application where Clients access the database Direct.
You have two lines of defence here. the function 'stat' will give you the last modify time. If it has not changed since the last time you read it, or wrote to it, your private copy items are still in date.
What to do Next, if the File Stamp has changed. In any case, we need to reload the data, if it affects the records we are dealing with. A Simple check sum will do!
Regards,
Bram
Bram van Kampen
|
|
|
|
|
Thanks a lot for your suggestion.
I think that Stat function is unix based. Can you please give me an example of to detect the structure member variable change using the stat function in windows.
|
|
|
|
|
I think you have already worked out the problem it is going to take you a lot of power to work out what has changed in the mapped file.
The best approach but the hardest would be to intercept the Writefile calls from the Model application since you don't have the code. The process is called IAT patching and you hook the model application write calls and simply send the data for each write call to your client before letting it drop thru to write to the mapfile as normal. There are a couple of IAT patching articles right here on Code Project. It obviously has the massive advantage that effectively it slows the model program down if your update dispatch is slowed and there is no searching to be done you are transmitting the changes as they are made. The downside is this is not something a novice can code it requires a level of experience.
The second alternative is to make an application that simply cycles around comparing the mapfile comparing the mapfile to a local copy of the last scan thru the file and transmitting changes as it encounters them. So you have a local copy of the mapfile as you last visited this position as you then find a change you hold the position in the file and then keep reading while you have differences. All you do then is send a simple structure File position, size of change, change data to the client. Then you continue back to looking for a changes. All the client does is grab a packet, move to the position given and copies the changed data. So the client copy just changes slowly to mirror the server mapfile at whatever rate the packets can be sent. This is how remote terminal services work sending your screen to another user.
The downside of the second alternative is you will often get your fields having part of current data and part old data. For you that is not to bad because you know the structure layout so you can probably carry field flags to indicate if they are currently half changed because you in the process of writing them.
Anyhow whichever technique you use this will not be a trivial task
In vino veritas
|
|
|
|
|
I was thinking a bit more about your problem and there is a possible all be it highly technical solution which is a thing called a file filter. It jogged my interest as to whether you could run a memory mapped file in a file filter so you can get all the raw file access commands and it appears you can
Memory Mapped Files in a File System Filter Driver[^]
It wouldn't be trivial but you would know exactly what and where is being written by the model program to the memory mapped file to then duplicate and send to your client.
In vino veritas
|
|
|
|
|
manoharbalu wrote: Now I need to transfer some of the data values that are changed to another application... A third application, not one of the two applications sharing the structure in memory?
"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
|
|
|
|
|
Hello, i've decided to code a application for our committees in our university section. The basic function of the program should be to inform students about upcoming events hosted by different student unions/committees.
Events will be stored in an SQL database. Every event will have a few datas like "Committee name" "Description of event" "Date". The idea is that the app will get all events from the database that hasn't already been. It will display these in a list inside the application. If a new event is uploaded to the SQL database the application will give away a push-notification. And user will be able to display it. I have experience in C.
My questions are
Is there good graphic libraries and is it possible to do this with ease in C++?
Is it possible to make a program like this work in Android and IOS?
Would also appreciate general tips for people that've made mobile applications
|
|
|
|
|
C++ is not very popular in standard mobile applications (and it is not recommended, see, for instance Getting Started with the NDK | Android Developers[^].
For the an Android platform, Java is the natuaral programming language (altough you migh as well use C# via Xamarin ).
|
|
|
|
|
As CPallini said C,C++ coding of Android is not for the faint hearted and I would not recommend it as things stand at current.
I can offer you a funny way into the problem for a medium level programmer which is to use the free Unity game engine. You write in C# and can run your code and debug it as a windows application on windows. Then you just select the target as android and it does all the conversion and crossing to Android for you.
There are several good sample applications right here on Code Project in the Unity section but the cross platform is this simple
Tutorial: Creating your first Unity Android App [2015 Update] « Rabidgremlin's Soapbox[^]
You have a bit of learning to do with the unity interface but there are plenty of tutorials. The SQL classes already exist as standards in Unity like they do in .NET and is rather trivial as most online games store data in/from server databases.
On the plus side all the finger swipe libraries exist already and you can develop a groovy application look on the UI using the graphics stuff
In vino veritas
modified 30-May-16 5:08am.
|
|
|
|