|
Hi,
In my application I am having dialog .I am receiving images from mobile and I am displaying Images on dialog. I have added vertical scroll bar to dialog.I am creating 8 static controls programatically on dialog and I am using these 8 static controls for Image display. At a time I am displaying 8 Images on Dialog.I am using Scroll bar to display all Images. I have written following code in my "displayImage" function.for every scroll I am calling this function.
for(int i = 0; i < 8; i++)
{
if((i != 0)&&(i%4 == 0))
{
x1 = 1;
x2 = 250;
y1 = y1+355;
y2 = y2+355;
}
myStatic[i] = new CStatic();
myStatic[i]->Create(_T(""),WS_CHILD|WS_VISIBLE|SS_BITMAP,
CRect(x1,y1,x2,y2),this);
image.Load(Image);
HBITMAP hbmp = image.Detach();
if(hbmp == NULL)
{
Error = GetLastError();
}
if(hbmp != NULL)
myStatic[i]->SetBitmap(hbmp);
}
First 8 Images are displaying Properly.After that If I scroll Scroll Bar dialog is showing first 8 Images first and It is displaying second 8 images.If I scroll third time it is showing first 16 images after that it is showing third 8 images and so on.Can anyone help me.
|
|
|
|
|
Probably your data structure is not getting cleared and still holds the images that you displayed earlier. Debug to check
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
I am facing this issue since few days. I tried so many options but no use
1)I deleted myStatic[i] variables after using static controls.
If I do that dialog is not showing any Images.here myStatic is local variable.
2) I declared member variables m_myStatic[8].No use.
|
|
|
|
|
Of course you delete the static control variables. But where and how do you store the images that later on get displayed in these static controls. My previous question was whether you clear the data from the structure and not the static controls themselves.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
I have made static control variable array as member variable.
In display Image function I am deleting static control variable array before creating new Static controls.
My code is working fine.Thanks for your reply
|
|
|
|
|
Dear all;
Recently our organization needs to convert a 3rd party’s MFC class library into managed code for usage in .NET. In the SDK, there is a header file and a dll library.
I only have little knowledge on wrapping unmanaged code to managed code. I would much appreciate if any one could give advice on how to implement.
Below shows the code in the header file for the dll library. Inside the “MainClass”, there are nested class, callback function and nested struct.
////////////////////////////Header File///////////////////////////////////////////////////////
#pragma once
#ifdef UNMANAGEDCODE_API_EXPORTS
#define UNMANAGEDCODE_API __declspec(dllexport)
#else
#define UNMANAGEDCODE_API __declspec(dllimport)
#endif
#include <sys/timeb.h>
class UNMANAGEDCODE_API MainClass
{
public:
MainClass ();
Virtual ~MainClass ();
Virtual bool StartUp(const TCHAR* pcszConfigFileName = NULL);
class NestedClass1
{
public:
// This is the entry for call back function
virtual bool OnNestedClass1() = 0;
};
Bool SetCallback(NestedClass1* callback); typedef struct NestedSruct1
{
unsigned int unId;
__timeb64 createTime;
}NestedStruct1;
const NestedStruct1** GetData(unsigned int& unCount);
};
////////////////////////////End of Header File///////////////////////////////////////////////////////
modified on Thursday, March 19, 2009 2:05 AM
|
|
|
|
|
anybody can help?
Thanks a million!
|
|
|
|
|
Try wrapping it in a managed C++ library. Basically, call the MFC DLL from within the managed C++ library, and then call the managed C++ library from your code. This is the easiest way to do it.
You will need delegates for the callbacks in the managed part. Search for it. There are examples of doing this all over the place.
|
|
|
|
|
Thanks for the kind reply, David.
Yes, now I learned how to wrap the class functions in a managed c++ library. But I am stuck with the callback function. Previously in our unmanaged C++ applications, in order to use the callback function in the legacy dll, we can just create a new class inheriting the NestedClass1 and implement the virtual function in the new class.
Below is the header file in the legacy dll.
///////////////////////////////
//Legacy dll header file
class MainClass
{
public:
class NestedClass1
{
public:
// This is the entry for call back function
virtual bool OnNestedClass1() = 0;
};
Bool SetCallback(NestedClass1* callback);
}
//End of legacy dll header file
//////////////////////////////
//Below codes shows how to use the call back function
/////////////////////////////////////////////////////
class NestedClass1Child:public NestedClass1
{
MainClass m_mainClass;
void Initialize()
{
m_mainClass.SetCallback(this);
}
virtual bool OnNestedClass1()
{
//Here I insert my code to get the data
int result = RetrieveData();
return true;
}
int RetrieveData()
{
return m_mainClass.GetData();
}
};
///////////////////////////////////////////////////////
As you can see from the above example in unmanaged C++, I just need to implement a child class of the NestedClass1 and then implement the virtual function "OnNestedClass1()".
But the issue now is: the managed class cannot inherit unmanaged class. I am wondering if the delegate is suitable for this case.
I would much appreciate if you could highlight more.
Thank you
Frank
David Knechtges wrote: Try wrapping it in a managed C++ library. Basically, call the MFC DLL from within the managed C++ library, and then call the managed C++ library from your code. This is the easiest way to do it.
You will need delegates for the callbacks in the managed part. Search for it. There are examples of doing this all over the place.
|
|
|
|
|
Problem Statement:
SetWindowsHookEx() won't permit the 2nd parameter to be a function in a class. Therefore, I have created a separate global function in my .cpp file "MouseHookWndProc" that will be called. However, how is it possible to reach functions in my (Dialog) class from the global function "MouseHookWndProc" ?
Source code:
S2000_CP_DLG::S2000_CP_DLG(CWnd* pParent) : CDialog(S2000_CP_DLG::IDD, pParent)
{
mouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHookWndProc, GetModuleHandle(NULL), NULL);
}
LRESULT CALLBACK MouseHookWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
char chTempText[100];
sprintf(chTempText,"MouseHook:0x%X",wParam);
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}
class S2000_CP_DLG : public CDialog
{
DECLARE_DYNAMIC(S2000_CP_DLG)
public:
void CpMessage(char* pszMessage, int nVal);
CEdit m_editMessages;
}
My Attempt to solve it:
The obvious solution for me was to make CpMessage() a static (as well as the m_editMessages since that member variable is used by the function).
This compiled, however Linking failed:
error LNK2019: unresolved external symbol "public: static class CEdit S2000_CP_DLG::m_editMessages" (?m_editMessages@S2000_CP_DLG@@2VCEdit@@A) referenced in function "protected: virtual void __thiscall S2000_CP_DLG::DoDataExchange(class CDataExchange *)" (?DoDataExchange@S2000_CP_DLG@@MAEXPAVCDataExchange@@@Z) S2000_CP_DLG.obj
void S2000_CP_DLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MESSAGES, this->m_editMessages);
}
The problem persists... and unfortunately adding "this->" to the DoDataExchange() didn't work
does anyone have any recommendations ?
|
|
|
|
|
Create a global pointer of your class.
S2000_CP_DLG* pThis = 0;
In the constructor or the OnInitDialog function assign the address of the object to the pointer.
pThis = this;
Now you can access the class members using pThis .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
nice!
pThis->CpMessage(chTempText,0);
compiled and linked without a hitch.
|
|
|
|
|
I am new user for SOM. how can i design a SOM of 15 neurons in a 3X5 rectangular grid.I am badly stuck up with this problem. Any answers.
|
|
|
|
|
What's a SOM ? a quick google does not return anything, hmm, usefull.
What have you done ? What have you research so far ?
Assuming it's for homework, how about asking your teacher, teachers' assistant, fellow students, ...?
This signature was proudly tested on animals.
|
|
|
|
|
Hello All,
A little question about memory allocation. Yes, nos and look heres greatly accepted...
I'm not sure how to word the question so I'll say what I want to do:
I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up.
Is this possible?
Thanks...
|
|
|
|
|
You can used shared memory, though the second program would have to start and open the shared memory before the first exited.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
Have a look at "memory mapped files"; these are files mapped into memory, or memory blocks mapped to an actual file, depending how you look at it.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Ylno wrote: . When this program finished I do not want to free up this memory location
This is not an option. It is freed or marked as free by the OS.
And could possibly be immediately used by another program and the earlier contents erased.
You should use persistent storage. Files, Registry ...
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Ylno wrote: When this program finished I do not want to free up this memory
Reminds me of good ol TSR.
Ylno wrote: want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up.
We have something similar at work. Yes you can do it. But you should host an all-time "memory-server". It's a complex thing. You'll have to do quite a lot of marshalings. A new process *Cannot* just starting using memory from another application. I've used those "memory-serving" services but don't know the implementation details. But the abstract idea resembles DCOM.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I like to keep as much as possible in RAM for fast read/write operations... my two suggestions:
Option 1
you could create a RAM Drive, then just save to a file. The two program share the data by accessing the same file in turn.
Option 2
You could also create a third program (that is started before the first program, and ends after the 2nd program) that sets up a shared file with CreateFileMapping():
char * pMyFilePointer = NULL;
HANDLE hMyFileHandle = CreateFileMapping((HANDLE)-1,
NULL,
PAGE_READWRITE,
0,
10,
"MySharedFile");
if (hMyFileHandle != NULL)
{
pMyFilePointer = (char *) MapViewOfFile(hMyFileHandle, FILE_MAP_WRITE, 0, 0, 10);
if (pMyFilePointer != NULL)
{
printf("file mapped to %p",pMyFilePointer);
*(pMyFilePointer+0) = (unsigned char)0;
*(pMyFilePointer+1) = (unsigned char)0xbb;
Then, your other two programs open the file with:
HANDLE hMyFileHandle;
char * pMyFilePointer;
hMyFileHandle = OpenFileMapping(FILE_MAP_WRITE, TRUE, "MySharedFile");
if (hMyFileHandle != NULL)
{
pMyFilePointer = (char *) MapViewOfFile(hMyFileHandle,FILE_MAP_WRITE, 0, 0, 10);
*pMyFilePointer = (unsigned char)0xAA;
}
|
|
|
|
|
Hi,
How do i convert my win32 console application to a window service in C++ ?
Regards,
Mayur M
|
|
|
|
|
|
Hello all,
I got the following makefile for the GD Library (http://www.fred.net/brv/chart/gdchart0.94b.tar.gz[^] :
GDC_INCL = .
GD_INCL = gd1.3
GD_LIB = gd1.3
CC=gcc
all: gdc_samp1 gdc_samp2 gdc_pie_samp
# compile the samples
gdc_samp1: gdc.o gdchart.o price_conv.o gdc_samp1.o $(GD_LIB)/libgd.a
$(CC) -o gdc_samp1 gdc.o gdchart.o price_conv.o gdc_samp1.o -L$(GD_LIB) -lgd -lm
gdc_samp1.o: $(GDC_INCL)/gdc.h $(GDC_INCL)/gdchart.h gdc_samp1.c
$(CC) -I$(GDC_INCL) -c gdc_samp1.c
gdc_samp2: gdc.o gdchart.o price_conv.o gdc_samp2.o $(GD_LIB)/libgd.a
$(CC) -o gdc_samp2 gdc.o gdchart.o price_conv.o gdc_samp2.o -L$(GD_LIB) -lgd -lm
gdc_samp2.o: $(GDC_INCL)/gdc.h $(GDC_INCL)/gdchart.h gdc_samp2.c
$(CC) -I$(GDC_INCL) -c gdc_samp2.c
gdc_pie_samp: gdc.o gdc_pie.o price_conv.o gdc_pie_samp.o $(GD_LIB)/libgd.a
$(CC) -o gdc_pie_samp gdc.o gdc_pie.o price_conv.o gdc_pie_samp.o -L$(GD_LIB) -lgd -lm
gdc_pie_samp.o: $(GDC_INCL)/gdc.h $(GDC_INCL)/gdcpie.h gdc_pie_samp.c
$(CC) -I$(GDC_INCL) -c gdc_pie_samp.c
# --- compile the lib ---
price_conv.o: price_conv.c
$(CC) -c price_conv.c
gdc.o: gdc.c gdc.h
$(CC) -I$(GD_INCL) -I$(GDC_INCL) -c gdc.c
gdc_pie.o: $(GDC_INCL)/gdc.h $(GDC_INCL)/gdcpie.h gdc_pie.c
$(CC) -I$(GD_INCL) -I$(GDC_INCL) -c gdc_pie.c
gdchart.o: $(GDC_INCL)/gdc.h $(GDC_INCL)/gdchart.h gdchart.c
$(CC) -I$(GD_INCL) -I$(GDC_INCL) -c gdchart.c
$(GD_LIB)/libgd.a:
cd $(GD_LIB) ; make -f Makefile libgd.a
# --- clean ---
clean:
rm -f *.o gdc_samp1 gdc_samp2 gdc_pie_samp
cd $(GD_LIB) ; make -f Makefile clean
My problem is :
1. How did the make file compile and link the gdc_samp1.c file ?
Really appreciated if anyone could have some answers ...I am a BIG NOOB in linkers...
Thanks,
Leslie
|
|
|
|
|
It follows the rules from all -> gdc_samp1 -> gdc_samp1.o -> gdc_samp1.c .
Just follow target dependencies to their associated targets, then follow those dependencies to their targets, until you get dependencies which have no corresponding target, at which point, either a) the file must exist, or b) there must be an implicit rule that knows how to make that file from some other file. Quite simple really.
Here's a useful intro to Makefiles[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Your question has little to do with linkers.
Make files follow a fairly simple syntax:
build_target1: dependency1.o dependency2.o build_target2 ....etc.
commands to build the build target
build_target2:
command(s) needed to build this build target.
So, looking at your make file:
# compile the samples
gdc_samp1: gdc.o gdchart.o price_conv.o gdc_samp1.o $(GD_LIB)/libgd.a
$(CC) -o gdc_samp1 gdc.o gdchart.o price_conv.o gdc_samp1.o -L$(GD_LIB) -lgd -lm
The build target "gdc_samp1:" is what defines all that is needed to make the gdc_samp1. So, make converts the line:
$(CC) -o gdc_samp1 gdc.o gdchart.o price_conv.o gdc_samp1.o -L$(GD_LIB) -lgd -lm
to:
gcc -o gdc_samp1 gdc.o gdchart.o price_conv.o gdc_samp1.o -L$(GD_LIB) -lgd -lm
For more info on make files: Clickety[^]
Hope this helps
|
|
|
|