|
Leslie Sanford wrote: I'm declaring/defining a const unsigned char array in an implementation file. I pass it to the above method
Pass it how?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Pass it how?
It's passed to the setter from the constructor. So in the Sawtooth.cpp file, I have the const array defined:
const unsigned char Sawtooth[] =
{
};
In my Wavetable.h file, I have the declaration:
extern const unsigned char Sawtooth[];
In my Oscillator class, I have an const unsigned char pointer member:
class Oscillator
{
private:
const unsigned char *wavetable;
public:
void SetWavetable(const unsigned char *wavetable);
};
In my constructor I do this:
#include "Wavetable.h"
Oscillator::Oscillator()
{
SetWavetable(Sawtooth);
}
In other words, I want the wavetable member to point to the Sawtooth array when an Oscillator is created.
[EDIT]
Oscillator.obj : error LNK2019: unresolved external symbol "unsigned char const * const Sawtooth"
That's part of the error message. It's as if the compiler wants to treat my Sawtooth array as an unsigned char const * const.
[/EDIT]
|
|
|
|
|
Again, this compiles and links for me
Leslie Sanford wrote: error LNK2019: unresolved external symbol "unsigned char const * const Sawtooth"
Are you sure you are linking Sawtooth.cpp?? The problem's in linking.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Again, this compiles and links for me
I should have paid more attention when you said this before instead of continuing to assume there was a problem with const.
If I include the header file in the implementation file that has the const array, everything works correctly; no more linking errors:
Wavetable.h:
extern const unsigned char Sawtooth[];
Sawtooth.cpp:
#include "Wavetable.h"
const unsigned char Sawtooth[] =
{
};
I'm not sure why, but including the header file in my Sawtooth.cpp file solved the problem. I can keep the const modifier.
|
|
|
|
|
Leslie Sanford wrote: I'm not sure why, but including the header file in my Sawtooth.cpp file solved the problem.
Cool.
Here's what the docs state:
"Declaration of const variables with the extern storage class forces the variable to have
external linkage. An initialization of an extern const variable is allowed in the defining
translation unit. Initializations in translation units other than the defining translation unit
produce undefined results."
I guess the definition needs the extern declaration as well on static const variables (?)
Cheers!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think I've figured out the problem. Arrays are const by default. That is the array variable is const, not its contents. This is illegal:
unsigned char a[100];
unsigned char b[100];
a = b;
So declaring an array as const...
const unsigned char a[100];
...seems to be interpretted by the compiler as unsigned char const * const, whatever the heck that is. An unsigned char const pointer to const... something.
At any rate, it does not evaluate to const unsigned char *. So when I tried passing it to the setter method, the compiler seemed to have a problem with that. If I remove the const modifier on the array, it compiles and runs ok.
What I was intending was to make an arrays contents read only. I haven't figured out how to do that.
|
|
|
|
|
The probem is not the const.
const unsigned char Sawtooth[] = {0,1,2,3,4,5,6,7,8,9};
If you try ...
Sawtooth[0] = 1;
...you'll see the compiler won't let you.
Passing Sawtooth as a const unsigned char * will work as well.
The assignment shown above won't work as you've seen - you need to deep-
copy the array contents from one to the other. Note if the destination is const
you won't be able to unless you cast away the const.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Dear gurus/colleagues:
Anybody knows what Win32 API function I can use to verify if a user account is already a member of a local or domain group?
I am working on a Oracle OS Authentication project. The user account I am talking about is for example: <domain_name>\<user_name> or <machine_name>\<user_name>.
The group I am talking about is for example: ORA_SEND_ALMUSER
I want to be able to use a Win32 API function to call and pass in the GROUP NAME as well as USERNAME to see if the username is a member of the groupname?
Any help would be greatly appreciated.
|
|
|
|
|
Hi,
I am designing a series of MFC controls for inputting basic information into a DirectX Modeling program. I would like to make those controls widely available by publishing them on this (or some similar) site. This is my first time doing this, so before I put them out there for feedback and general use, I thought I'd get some input on what design patterns would be easiest or most conventional to use.
Basically I am working on a control that will allow a user to input parameters for the following basic DirectX meshes:
Polygon (2 params)
Box (3 params)
Sphere (3 params)
Cylinder (5 params)
Torus (4 params)
Text (3 params)
and it's materials (10 params, or one struct).
So as you can see this control will contain a lot of information. Should I allow the user to access this material through one giant struct or wrapper class containing all the data, or by memberwise retrieval? Should the user gain access to the data by references or by values?
Any references on MFC control design patterns appreciated.
Thanks - Jason
|
|
|
|
|
how do i open a CStdioFile for writing such that i dont loose my previous data that exists in this file??
CStdioFile file;
file.Open("Temp1.dat",CFile::mode????);
????-> i tried using modeNoTruncate, modeReadWrite , but may be thats not the solution!!
|
|
|
|
|
OK i tried using the following and it worked. If any body has a better solution then please suggest:
CString line_feed='\x00A';<br />
CStioFile file;<br />
file.Open("Temp1.dat",CFile::modeReadWrite);<br />
file.SeekToEnd();file.WriteString(line_feed);<br />
CString str="watever u want to put";<br />
file.WriteString(str);<br />
file.Close();
|
|
|
|
|
Hello,
I have setting a background image into a ListCtrl with SetBkImage() method.
But the image is showed with a scroll, like the texts in the rows.
How could I disable the scroll of the background image? I hope to put the image fixed in the background of ListCtrl.
Any idea?
Thanks,
Cris.
|
|
|
|
|
|
I am working on an application that has the ability to open files using MFC and Visual Studio .Net 2003. I need give the user the option not to continue opening the file for special cases or scenarios. The determination is based on a keyword setting in an XML tag. Using the Serialize method, I was able to modify the software to not continue loading the file. However, it loaded it anyways but not completely. Do you know how I can prevent it from loading a file completely?
|
|
|
|
|
Have your Serialize method throw a CArchiveException. This will cause CDocument to totally cleanup the partially loaded file.
AfxThrowArchiveException(CArchiveException::none);
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Well, i need to execute a function at the change of day(or possibly a time defined by user). I have used CWnd::SetTimer()at one place for 5 secs trigerring. How can i do it to trigger every day(or hour)...i dont think it would be advisable to plainly convert a day's value into milliseconds and pass it to SetTimer()!!! What way can i achieve this??
|
|
|
|
|
It looks like SetTimer has a maximum interval of 24.85 days (if I did the math correctly).
Hours or a day shouldn't be a problem.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Just think of how many milliseconds are lost each day, I would go for QueryPerformanceCounter but then some say the MM timers are better :p
|
|
|
|
|
|
Why don't you just make use of windows' Task Scheduler?
|
|
|
|
|
Task scheduler?? i dont know anything about it...
Right now i have used SetTimer() for 6lac count; that's 10 mins....
do you think there could be a problem using SetTimer()???
|
|
|
|
|
Hi,
I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place.
GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following;
<br />
CRect btnRect;<br />
btn1.GetWindowRect(btnRect);<br />
<br />
::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW); <br />
This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still).
I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct?
If so, how can I find it programatically?
Thank you very much for your help.
|
|
|
|
|
SetWindowPos coordinates for child windows are relative to the client
area of the parent window.
You are using window coordinates relative to the screen.
Try GetClientRect instead of GetWindowRect.
What Roger said
Also, MoveWindow is simpler and more appropriate for this than SetWindowPos.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
MapWindowPoints() or ScreenToClient()
CRect btnRect;
btn1.GetWindowRect(btnRect);
ScreenToClient(&btnRect); //assumes that this is the parent of btn1
btn1.SetWindowPos(wndTop, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);
|
|
|
|
|
I need someone with Orcas to test the following code. It compiles just fine under Comeau C++ 4.3.9 in strict mode (Comeau is supposedly the "most Standards-compliant compiler in existence") but fails with an error under VS.NET 2003 (VC++). According to the ANSI Standard (section 10.3.5 in my Draft copy), I can't find any reason for it to fail.
class MyBase
{
public:
MyBase() {}
virtual ~MyBase() {}
virtual MyBase *Copy() const
{
return new MyBase(*this);
}
};
class MyBase2
{
public:
MyBase2() {}
virtual ~MyBase2() {}
virtual MyBase2 *Copy() const
{
return new MyBase2(*this);
}
};
class MyDerived : public MyBase, public MyBase2
{
public:
MyDerived() {}
virtual ~MyDerived() {}
virtual MyDerived *Copy() const
{
return new MyDerived(*this);
}
};
int main()
{
return 0;
}
|
|
|
|