|
Hi,
I think I have hit the final roadblock in my bid to learn how to be comfortable with DLLs. I spend the whole of last night trying to figure this out, but to no avail.
I wanted to create a custom window control which all it does is draws a rectangle and blits a bitmap in it. I did it without a DLL and it worked without a hitch. Now, I used the same code and tried to write a DLL interface to it as follows:
//----------------------------------------------------------------------------------long _stdcall InitControl(HINSTANCE instance, HWND hwnd, HBITMAP hBitmap, int x, int y, int width, int height)
{
View::RegisterClass(instance);
//Offset::RegisterClass(instance);
background = new Bitmap(hBitmap);
pCtrl = new Controller(hwnd, background);
SetWinLong<controller *=""> (hwnd, pCtrl);
return 0;
}
//----------------------------------------------------------------------------------
The View::RegisterClass(instance) line is supposed to register my window control class. Using the debugger, I see that the RegisterClassEx(WNDCLASSEX) returns a non-zero value basically indicating success.
Now, in my controller class I try to create the window as:
View::MakeWindow (HWND, hwndParent, childID);
How the CreateWindowEx(...) returns zero. I verified all the parameters and they are not null. I even verified the parent handle (coming from the VB call) through Spy++ and it is indeed the same window with the right HINSTANCE. The error code string is "Cannot find window class". So, I am guessing the window did not get registered.
However, this same code works in a normal program. So, are there some rules when I am registering my own windows in a DLL. Do the parent window and the child window have to share the same DLL or something like that? I cannot understand what I am doing wrong.
Also, the VB declaration is like this:
Public Declare Function InitControl Lib "C:\BOXDLL.dll" (ByVal instance As Long, ByVal hwnd As Long, ByVal back As Long, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As Long
and the call is:
InitControl App.hInstance, Me.hwnd, Me.Picture.Handle, 10, 10, 900, 200
I would really appreciate some help here. I have inching towards learning this for a whole month now and I am so close. However, this is the toughest problem I have encountered so far.
Also, I am not using MFC.
If you live around Stuttgart and help me, I will do your laundry for a week
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Are you creating an ActiveX control or what?
Need more input.
Trust in the code Luke. Yea right!
|
|
|
|
|
Nope, no ActiveX. However, I fixed it. So, it is all ok now
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
I am a real beginner in C programming.
I would like to create a sine wave and sample it. How do i start?
Any samples of programs are welcome
Thx
F.K
|
|
|
|
|
try something like this
double y [SAMPLES_NUMBER] ;
for (int i = 0 ; i < SAMPLES_NUMBER ; i++ )
y[i] = sin ( i ) ;
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Or like this:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main(int argc, char **argv){
double h, x,i,m;
h=15; // number of samples
m=2*PI/h; // sample interval
// create one sinus wave = 360 dgr
for (i=m; i<2*PI;) {
x = sin(i) ;
printf("At time %2.1f %f\n", i, x);
i=i+m;
}
return 0;
}
and display like this
http://www.charlespetzold.com/pw5/SineWave.c
jhaga
|
|
|
|
|
Hi,
I am using VC++, i thought a C code could work with VC++ but when i compile the code, it does not recognize printf
What is the problem?
F.K
|
|
|
|
|
Start with making a new console application with VC++
for printf to work you must have
#include <stdio.h>
if it complains something about precompiled headers then
choose the file, press the right mouse button, settings and
change Category to Precompiled Headers, and check
Not using precompiled headers
instead of printf you can use
cout << i << " " << x << endl;
jhaga
|
|
|
|
|
Do a search of MSDN, search the www, and sites like codeproject and sourceforge (there are more than one example of drawing some-thing as simple as sin).
When plotting points(/pixels/pels) under windows (using the cartasion (miss spelled) coordinate system) you will need to to set the origin, to the center of the client area [Normaly the origin is the upper left hand courner of the client area, but you can change it before you start drawing].
Sorry I could not provide a progaming example, but I do not have any code (at that low a level) to give you.
Trust in the code Luke. Yea right!
|
|
|
|
|
Dear Friends
Kindly write to me about a function to set the Aspect Ratio in WinAPI.
IF possible kindly give an example.
Thanking you.
Adarsh
|
|
|
|
|
I want to use some ATL classes in my WIN32 application. I want to use my application in Internet so I don't want to add extra dll with my application.I want to know if I use these class should I any dll to my application like MFC or ATL dll's is part of Windows installation?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
How to show an explorer style file dialog. I tried giving the OPENFILENAME Flags as OFN_EXPLORER. But still its showing me the old style file open dialog. What else should I do? Saw a member FlagsEx for m_ofn datamamber. But when i give it, it shows error. I am using Win2000. Kindly help......
================
CFileDialog fd(true);
fd.m_ofn.Flags=OFN_ENABLESIZING|OFN_EXPLORER ;
fd.DoModal();
Thanks...
Vini
|
|
|
|
|
If you need an Open dialog with Outlook-style bar on the left side then look here[^].
rechi
|
|
|
|
|
|
i tried adding the manifest file to the project,but it doesn't work.
i guess there must be something else to do to make this.
modified 1-May-21 21:01pm.
|
|
|
|
|
You must call InitCommonControls() at the start of your program.
Software Zen: delete this;
|
|
|
|
|
So, I'm experiencing the blackout of my life.
I currently perform a code review and got stuck on the following (I did a couple of simplifications for this CP demo purpose):
char* pText = "";
if(...condition A...)
pText = "Some text";
else if(...condition B...)
pText = "Another text";
I don't use this style myself, because I've been taught not to.
My understanding of the above code is that asignment 1 is ok to do, because the compiler will tell the program to allocate memory for "" at startup and point pText to that memory. However, I 'm stumbling on the "correctness" of assignments 2 and 3 - will they segfault at some time, or are they completely and utterly safe and legal? I could imagine that memory is also allocated for those texts at startup, so that redirecting pText to one of them will be safe after all.
Gee, I really feel 15 years less experienced than I am right now...
Thanks for any input.
|
|
|
|
|
I don't think assignments 2 and 3 are legal at all. Imagine for a moment if you had the following statement:
char cSomeChar;
pText[ nSomeIndex ] = cSomeChar;
Either one of those strings is considered a constant so you can't really alter their values.
Assume for a moment that pText will point to another text string later. Will the compiler deallocate and reallocate memory for the pointer again? How will it distinguish from a case where memory is being allocated by the programmer or by the compiler? It would have been great if compilers had those capabilites, but to my knowledge there aren't any that can do that. That's why I believe those assignments are totally illegal. To tell you the truth you are making me question what I know about pointers (which isn't a lot ).
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Toni78 wrote:
I don't think assignments 2 and 3 are legal at all
Actually, after some thought, I'm quite convinced that the assignments 2 and 3 are legal and safe, since they point to string literals allocated at startup.
But another question is whether this is a Good Style or not...
|
|
|
|
|
I don't see any problem with memory allocation but should pText be
initialised to "" or NULL. If you set char* pText=NULL and later
try to use it then the program crashes(MFC). pText="" will not crash
but it can be more difficult to debug.
jhaga
|
|
|
|
|
Because "Some text" and "Another text" are static text, the compiler has already made room for them. pText can point to them because they indeed exist in memory.
|
|
|
|
|
The code is legal but not safe. You should use a const char * (LPCSTR) to point to this string to signify that the contents should NOT be modified.
|
|
|
|
|
In my header file I have:
<br />
#include <iostream><br />
#include <list><br />
<br />
class mp {<br />
private:<br />
class element {<br />
public:<br />
double x;<br />
double y;<br />
double z;<br />
bool operator<(const element& a ) { return z < a.z; }<br />
friend std::ostream& operator<< (std::ostream& str, <br />
const element& e ) <br />
{<br />
return str << "(" << e.x << "," << e.y << "," << e.z <<<br />
")";<br />
}<br />
};
typedef std::list<element> elementList;<br />
elementList points;<br />
public:<br />
mp();<br />
mp( elementList Points );<br />
void print();<br />
};<br />
in my cpp file I have:
<br />
#include "mp.h"<br />
<br />
mp::mp() {}<br />
<br />
mp::mp( elementList Points ) {<br />
points = Points;<br />
points.sort();<br />
}<br />
<br />
void mp::print() { <br />
using std::cout;<br />
for ( elementList::const_iterator e = points.begin(); e !=<br />
points.end(); e++) {<br />
cout << e << endl;<br />
}<br />
}<br />
Get get this error ....
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::list<class mp::element,class std::allocator<class mp::element> >::const_iterator' (or there is no
acceptable conversion)
what do you think?
please help me out
|
|
|
|
|
try
cout << *e << endl;
instead.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|