|
LPSTR strA;
LPSTR strB[ 100 ];
<br />
SomeFunc( &strA );
SomeFunc( strB );
When passing arrays around, it is wise to also pass the number of members. To make life easier just use std::vector.
std::vector< LPSTR > vStr;<br />
<br />
BOOL SomeFunc( std::vector< LPSTR >& vStrings );<br />
|
|
|
|
|
WalderMort wrote: When passing arrays around, it is wise to also pass the number of members. To make life easier just use std::vector.
He's not asking to pass arrays around, he asking how to pass a pointer to a pointer into a function.
Kinda like here's pointer, allocate something for me then modify my pointer to point to it.
|
|
|
|
|
Well, maybe your right. I got caught up in the LPSTR* thing but now that I reread it, your probably right.
My bad
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">nitinmx wrote:</div>BOOL SomeFunc( LPSTR* arString )</blockquote>
LPSTR* is a pointer to a pointer. I am assuming you want the function to allocate some memory and modify your pointer to point to it. If this is what your after, here's a sample...
int CTestPPView::SomeFunc(LPSTR* pPointer)
{
ASSERT(pPointer);
ASSERT(*pPointer==NULL);
char* pString="This is a test";
int nLength=strlen(pString)+1; // Add one for null terminator
// Modify the passed in pointer to point to allocation
*pPointer=new char[nLength];
if (*pPointer) {
strncpy(*pPointer,pString,nLength); // Copy some string to it
return nLength;
}
return -1; // Error
}
// In some method elsewhere...
LPSTR lpString=NULL;
int nLength=SomeFunc(&lpString);
if (lpString) {
TRACE("%s\n",lpString); // Just to display in debug
delete[] lpString;
}
-- modified at 12:14 Saturday 25th August, 2007
UPDATE: Now that I reread your post, I realize LPSTR* is not correct for what you are apparently trying to do. Waldermort appears to have interpreted correctly what you are asking for so just ignore my post.
|
|
|
|
|
Hello Friends i am using Win32 Application. And i want my dialog box to have some color on it rather than same old boring color..
can anybody plz tell me how to colour the dialog box and put pictures on it.
|
|
|
|
|
you can set the window color when u Registering Window class, or by using SetClassLong function.
SetClassLong( hWnd , GCL_HBRBACKGROUND , (LONG)hBrush) ;
handle WM_CTLCOLORDLG if u have a dialog application.
u can use CreatePatternBrush to paint picture.
|
|
|
|
|
i want to clear the previous data on buffer and to display the new string on the edit box. i am having problem when i write on the port n read it as well by loopback technique and try to clear it using purgecomm it doesnot delete the previous string and display it along with new string. any help would be appriciated
|
|
|
|
|
When a DLL is loaded, is there a way to determine what loaded it; the application or another DLL?
In other words, say application APP loads DLL_1. DLL_2 get loaded. Can DLL_2 determine whether it was loaded by APP or DLL_1?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
Unfortunately not since that's not what I asked, but thank you anyway. I have a DLL that needs to know at runtime what loaded it.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I believe that if you call GetModuleFileName(), it will return the file name for the parent process, if it is an executable file; read up on it on MSDN.
As written by MSDN for the hModule parameter, "If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process"
Hope this helps!
--PerspX
"Nowadays, security guys break the Mac every single day. Every single day, they come out with a total exploit, your machine can be taken over totally. I dare anybody to do that once a month on the Windows machine." - Bill Gates
|
|
|
|
|
Not to be too rude, but I know that. I was EXTREMELY clear that I needed to know what executable loaded my DLL, not what process. In other words, an application may load a DLL, which in turn may load my DLL. I need to know what loaded my DLL at runtime. (There may be several executables between the main application and my DLL.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
OK I was just trying to help.. You know I read somewhere on the Internet that there are some data structures out there which are stored and set when DLL's are loaded which has all information about the DLL, such as reference count. Maybe there is a variable which has whether the DLL was loaded by an EXE or DLL. You'll have to find this yourself though as I'm not doing your research.
--PerspX
"Nowadays, security guys break the Mac every single day. Every single day, they come out with a total exploit, your machine can be taken over totally. I dare anybody to do that once a month on the Windows machine." - Bill Gates
|
|
|
|
|
Joe Woodbury wrote: (There may be several executables between the main application and my DLL.
And in this case, GetModuleFileName(NULL, ...) would return the name of the EXE whose address space contains your DLL, regardless of how many other EXEs were loaded first. For example:
A.EXE --> CreateProcess() --> B.EXE --> CreateProcess() --> C.EXE --> implicit/explicit linking --> YOUR.DLL
In this scenario, GetModuleFileName(NULL, ...) would return C.EXE.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Ahhhh, I KNOW THAT, that's the point of my question.
I shake my head and wonder why I bothered posting this question.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I actually understood your question as posted but thought 2 things:
1. I don't think there is any ways of knowing.
2. I can't think of a reason why you would want/need to know.
I thought the best you can do is determine if the dll was loaded via a static binding or a LoadLibrary() call:
http://msdn2.microsoft.com/en-us/library/ms682583.aspx[^]
lpvReserved
If fdwReason is DLL_PROCESS_ATTACH, lpvReserved is NULL for dynamic loads
and non-NULL for static loads.
If fdwReason is DLL_PROCESS_DETACH, lpvReserved is NULL if FreeLibrary
has been called or the DLL load failed and non-NULL if the process is terminating.
I can't think of a way off-hand to determine if it was an exe or other dll that was statically bound to your dll. The best i can think of is to look at the list of statically linked dll's for the exe and see if your dll is in the list, if so it was the exe, if not then another dll.
To determine if it was an exe or other dll that called LoadLibrary() to load your dll, i would walk the stack and check the address of the function that called LoadLibrary(), and from that get it's module.
I have two questions:
1. What is the scenario you have where you need to know this.
2. When can we expect an article describing how to do it.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote: 1. What is the scenario you have where you need to know this.
Security. We have an embedded XP system. We expose a series of APIs to third parties which allow a subset of operations depending on their contract with us. They can't, however, use the underlying DLLs of this API directly. Our concern isn't developers using the low level APIs maliciously, but as a shortcut to meet deadlines. We must keep this as light weight, non-intrusive and automated as possible for many reasons.
(Figuring out ahead of time that a DLL is being loaded statically is easy and we'll do that. It's when they load it dynamically that's more problematic.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Interesting.
I don't think there is a perfect solution for what you want.
e.g.
User writes an exe, the exe first loads your API dll, which then properly loads your low-level dll.
Later in the exe they load a low-level dll directly, at this point i don't think you will get a DllMain(DLL_PROCESS_ATTACH) call in the low-level dll, i just think it's ref count will be increased.
If it is to prevent 'casual' attempts then you may want to export a NONAME init function from the low-level dll that takes some cryptic params. Your API dll would then call this after loading the low-level, but before using any of it's functions. A 3rd party dev would have to hack your API dll to see what is going on. The down-side here is that the low-level functions would have to check some init flag to see if everything is ok - a little extra overhead. I've seen this method used by a number of 3rd party libraries.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
It seems that this must be done programmatically at run-time, rather than design time (which is what I'm used to with VB), but I haven't found any example code.
Does anyone have example code to changing the font color of a Static Text and Edit Control ?
thanks !
|
|
|
|
|
If you respond to the WM_CTLCOLOR message in the control's parent,
you can set the text color and background color on the passed DC.
Are you using Win32 APIs or MFC?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am using MFC.
I've added the OnCtlColor() event and it changes the color, but the backgrounds of the edit box and static text box remain grey instead of transparent:
HBRUSH S2000_CP_DLG::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch ( pWnd->GetDlgCtrlID() )
{
case IDC_FW_VERSION: //Static Text box
case IDC_MESSAGES: //Edit Control
pDC->SetTextColor(rgbColor_RED);// Set the text color to red
pDC->SetBkMode(TRANSPARENT);// Set the background mode for text to transparent
break;
}
return hbr;
}
I made sure the WINVER is defined to 0x0501 to compile for XP, but still, the background is not see-through.
Is there a fix for the background transparency ?
|
|
|
|
|
You need to return a handle to a brush that you've created/obtained
instead of returning the default brush...
CBrush m_RedBrush;
...
m_RedBrush.CreateSolidBrush(RGB(0xFF,0x00,0x00));
...
HBRUSH S2000_CP_DLG::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch ( pWnd->GetDlgCtrlID() )
{
case IDC_FW_VERSION:
case IDC_MESSAGES:
pDC->SetTextColor(rgbColor_RED);
pDC->SetBkMode(TRANSPARENT);
break;
}
return m_RedBrush;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
using the solid red brush makes the static text and edit control backgrounds red.
What I really wanted is have the bitmap on the Dialog visible through the Static Text and Edit Control.
|
|
|
|
|
You could return a NULL brush:
return (LRESULT)::GetStockObject(NULL_BRUSH);
This works on static controls, but I have not got it to work on edit controls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I just tested - returning a NULL brush works unless XP visual styles are enabled.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|