|
Isn't there a way to feed the data file to the linker directly via a custom build setup? I'm trying to write my code so it'll be platform independant, so I wanted to avoid getting the windows resource sceme involved. Is there maybe just little command line app that can generate a VC++ compatible obj from a data file or something?
|
|
|
|
|
The minute you depend upon a specific linker option to do something like this, your code become platform dependent.
I don't know if there is a command line app does what your asking. If there is and you use it, then you're again, making your code platform dependent.
Here's how I to do it, when I needed to import such data files into my code:
1) Write a small program that takes my data file type and generates a file that contains an array in C/C++ code, that contains the data.
2) Include the generated file in the project.
That's all there is to it. Now the name of the array is a pointer to your imported data.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
>The minute you depend upon a specific linker option to do something like this, your code become platform dependent.
Well, compiling and linking is always a platform dependant proccess isn't it? The issue here is the ease in which you can get an app set up to build on different platforms. Right now all I really concerned about is that all my C code is platform independant. If it's a little tricky to build so be it, I'll cross that bridge when I come to it.
>I don't know if there is a command line app does what your asking. If there is and you use it, then you're again, making your code platform dependent.
That depends. If the app I used was also platform independant, then it wouldn't be a problem.
>Here's how I to do it, when I needed to import such data files into my code:
1) Write a small program that takes my data file type and generates a file that contains an array in C/C++ code, that contains the data.
2) Include the generated file in the project.
>That's all there is to it. Now the name of the array is a pointer to your imported data.
A little messy, but not a bad idea. I'll take it into consideration if I can't find a way to do it the way I wanted. I was thinking I might see if there was a way to rig it up with NASM, but of course then I'm becoming CPU dependant. That isn't actually a real problem at the moment, but it could come back to haunt me later. Hmm... am I the only one who thinks that C needs a standard directive for embedding a data file into a compiled program?
|
|
|
|
|
Xzyx987X wrote:
compiling and linking is always a platform dependent process isn't it?
Yes, compiling and linking are alway platform dependent. What I was referring to, was dependents on a particular linker option; which limits you to only linkers that have that option.
Xzyx987X wrote:
That depends. If the app I used was also platform independent, then it wouldn't be a problem.
If the app produces .obj files, then it can't be platform independent. It would have to know the format of every .obj file produce by every compiler out there (not possible).
Xzyx987X wrote:
I'll take it into consideration if I can't find a way to do it the way I wanted.
In the time it took you to receive and reply to my last message, I could have written the require program (and so could you).
Xzyx987X wrote:
Hmm... am I the only one who thinks that C needs a standard directive for embedding a data file into a compiled program?
Probably.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
See if this article helps.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I'd rather not do anything that involves hacking up the exe once it's compiled. Talk about a messy build process...
|
|
|
|
|
I'ma C++ newbie, and i'm trying to find a useful occasion where copy constructors can be used. It's quite useless learning the thing and then not knowing when or what to use it for.
MO money, mo problems
|
|
|
|
|
myclass m1 = m2; // implicit call to copy constructor
myclass m1(m2); // explicit call to copy constructor
m1 = m2; // explicit call to operator=
m1(m2); // error if tried here
The compiler will generate a bitwise version of the copy constructor it you do not define your own version. This is ok as long as you class, and its data types, does not contain in allocated data pointers. If they contain data pointers, then you'll have two classes pointing to the data and when one of the class is destoyed the data pointed to is destoyed. What that means, is the data pointer in the class that still exist is now invalid and anything you try to do with it (including freeing it) it will cause problems (probably crash your program). Therefore, you need to create your own copy constructor that allocates memory for its self so you can make a copy of the stored data.
Note what I just said about copy constructors also applies to operator=, except that if you supply a copy constructor and you don't supply an operator=, then the compiler should generate an operator= that uses your copy constructor (instead of a bitwise copy). Therefore, if you supply a copy constructor, you should not need to supply your own operator=.
That should give you a good start at understanding why copy constructors are important. After all, whether you supply your own or the compiler generates one, there is going to be a copy constructor.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
hi everyone..
i have a little problem with UPDATE_COMMAND_UI...it seems to work perfectly in non-dialog based programs but when it comes to dialog-based ones the following are noticed:
1-the OnUpdateFileNew function(which is called by the ON_UPDATE_COMMAND_UI) is not called until my menu item is pressed...it should be called before the item is displayed..
2-the CCmdUI* in the previous function belongs to a weird class called CTestCmdUI which is in wincore.cpp...it should be a pointer to a CCmdUI class in cmdtarg.cpp....
actually i'm new in this update command ui thing so it will be very appreciated to explain more about it to me...
thanx..
|
|
|
|
|
MFC doesn't implement the automatic update of UI elements for dialog based apps.
If you want to have this functionality for a menu in a dialog based application you could do something like the following (it wasn't thoroughly tested and makes use of undocumented functions so, as always, use it at your own risk):
In you dialog class declaration, add the following member:
afx_msg void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
In your dialog's cpp file, make the following changes (change "YourDialog" to the actual class name of your dialog too):
BEGIN_MESSAGE_MAP(YourDialog, CDialog)
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
void AFXAPI AfxCancelModes(HWND hWndRcvr);
void YourDialog::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
AfxCancelModes(m_hWnd);
if (bSysMenu)
return;
ENSURE_VALID(pMenu);
CCmdUI state;
state.m_pMenu = pMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
state.m_pParentMenu = pMenu;
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = GetTopLevelParent();
if (pParent != NULL &&
(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nItemIndex = 0; nItemIndex < nIndexMax; nItemIndex++)
{
if (::GetSubMenu(hParentMenu, nItemIndex) == pMenu->m_hMenu)
{
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue;
}
state.DoUpdate(this, FALSE);
}
else
{
state.m_pSubMenu = NULL;
state.DoUpdate(this, state.m_nID < 0xF000);
}
UINT nCount = pMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
Hope that helps, and please let us know if it worked or not.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi everybody. I'm a C++ newbie so if my questions seem to shock the life out all you veterans out there plz forgive me. I"m just having problems trying to understand what on earth a copy constructor does or is used for (assuming that it does have a use in our current existing life!) If someone could just give me a clear example(s) on this, I would appreciate it. I would also like a little explanation on what it might (it at all) be used for. Thanxs (again i apologize if my questions seem to ignorant )
Respect nerds, chances are you'll be working for one!
|
|
|
|
|
|
I checked that one out already. Still didn't make sense. Plus somehow my computer's been acting really weired with the online encoding, so im not even sure what i'm looking at is what it's supposed to be (i'm getting extra parenthesis and brackets in unusual locations). Any other suggestions??
|
|
|
|
|
|
Hi,
I am doing a project on win32 threads. I have created a event inside the thread and looping using while() and waitonsingleobject() until the condition is met.
For some reason I have to use thread. I am calling the thread in WM message but I want to wait there itself(where I called the thread) until the thread is finished. How can I do this???
I tried using a global boolean variable setting that to true when the thread is started and to false when the thread is terminated, and creating another evet to wait until this boolean variable becomes false.But it did'nt work very well.my app started hanging...how can i solve this..
Thanks in advance.
|
|
|
|
|
You message loop should run independent of the thread.
Only if your program is terminating should the message loop ever wait on the thread.
If you supply the window handle into a variable the thread can access, the thread can post a registered window message back into your message handler, which your handler can detect, to know that the thread is done processing. Otherwise, the message handler can go about its regular business and your progrma will not appear to be hung.
|
|
|
|
|
Dear Group,
I am trying to get the source (src) of images in web pages. I am using IHTMLElement2 (IE's API) to get the information regarding the html elements. I successfully extracted images, but i dont know how to extract the src of images.
for example: if you have,
then how would you extract "/intl/en_uk/images/logo.gif" using the IE's API !!
I know i can do that by searching through the html source code, and do a similarity match for the word (src) ... that would be too time consuming
does anyone know an easy better way ???
cheers
llp00na
|
|
|
|
|
llp00na wrote:
I am using IHTMLElement2 (IE's API) to get the information regarding the html elements. I successfully extracted images, but i dont know how to extract the src of images.
If you got the IHTMLElement2 for the image tag, try querying for IHTMLElement interface and then using getAttribute() on it.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
llp00na wrote:
I know i can do that by searching through the html source code, and do a similarity match for the word (src) ... that would be too time consuming
It depends on the size of the page (i.e. the HTML) and whether image links are coded in plain ol' HTML vs. being injected into the document using JavaScript.
See the LinkChecker example in this[^] article. You may be able to use it with almost no code changes.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
Hi. Iwant to get the owner name of a file or directory. I hope to get the creators name.
Thus I used the GetFileSecurity to get the file security id and then the GetSecurityOwnerDescriptor to get the account security id. Then, I stack.
According to the manual you have to use the LookupAccountSide specifing two buffers as parameters: One to get the account name and another to get the domain name. Also according to them you need to give the current size of the buffers. The call will fail if one of buffer is not large enough and it will return the correct buffer sizes. It will also fail for other reasons like network failure etc.
Does anyone knows what is the error returned due to a buffer failure? Is it the same error for both buffers or a different one? How many calls do I need until I correct the buffers (by reading the sizes and allocating the buffers) until I get anyothe legitimate failure??
Why MicroSoft, NEVER, NEVER, NEVER documents the possible ways that a function may fail??? Is this a developers friendly company???
|
|
|
|
|
I use something like:
PSECURITY_DESCRIPTOR pSecurityDescriptor;
PSID pSidOwner;
SID_NAME_USE rSidNameUse;
DWORD dwAccountSize,
dwDomainSize;
char *pszAccount,
*pszDomain;
if (GetNamedSecurityInfo(
(LPSTR) lpszObjectName,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,
&pSidOwner,
NULL,
NULL,
NULL,
&pSecurityDescriptor) == ERROR_SUCCESS)
{
dwAccountSize = 0;
dwDomainSize = 0;
LookupAccountSid(NULL, pSidOwner, NULL, &dwAccountSize, NULL, &dwDomainSize, &rSidNameUse);
pszAccount = new char[dwAccountSize];
pszDomain = new char[dwDomainSize];
if (LookupAccountSid(NULL, pSidOwner, pszAccount, &dwAccountSize, pszDomain, &dwDomainSize, &rSidNameUse) == TRUE)
...
delete [] pszAccount;
delete [] pszDomain;
LocalFree(pSecurityDescriptor);
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks. I do not think that the GetNamedSecurityInfo versus a combination GetFileSecurity,
GetSecurityOwnerDescriptor will make much difference. To my view if I have two functions I localise slightly the failure. In the GetFileSecurity I know that I faild to get the file SID whilst with GetSecurityOwnerDescriptor I know I faild to get the owner account SID. Unless the GetNamedSecurityInfo returns a different account SID from the proposed combination.
My real question is again the two calls of the LookupAccountSid. Like your case how do I know that the first one faild due to zero buffer size and not for any other reason (e.g. the file is across the network and the network went down when I was examining, or the file is been deleted and been left with a duggling pSidOwner). Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL?
Any detailed documentation on the failures will be great.
Its an art to keep things simple
|
|
|
|
|
Dimitris Vikeloudas wrote:
Like your case how do I know that the first one faild due to zero buffer size and not for any other reason
It returns ERROR_INSUFFICIENT_BUFFER .
Dimitris Vikeloudas wrote:
Also will one call set both buffer sizes or one of them and then will fail again because the second buffer is still NULL?
They are both set to the necessary size.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
At a breakpoint I see:
m_pParent = 0x003330d60 {CMainFrame hWnd=0x00060643 {unused=???}}
////
I am passing the MainFrame CWnd object into a constructor and assigning the object to m_pParent.
What I want to know is what the hex values assigned to m_pParent and hWnd mean...and why the values are different? Isn't hWnd a pointer to the Windows window??
Thanks.
Jerry
|
|
|
|