|
EvScott wrote: BOOL CYourDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//pointer to your button
CButton *pButton = (CButton*)this->GetDlgItem(IDC_BUTTON1);
pButton->EnableWindow(FALSE);
}
Thanks for ur response. when i entered the above code i got a warning
"warning C4005: 'IDC_SIZE' : macro redefinition
see previous definition of 'IDC_SIZE'"
Please tell me what is wrong
Thanks
|
|
|
|
|
Compiler Warning (level 1) C4005
'identifier' : macro redefinition
The given identifier was defined twice. The compiler used the second macro definition.
Sudeep, observe the above which is an excerpt from MSDN. Make sure that you have only ONE identifer named "IDC_SIZE". The compiler will complain otherwise. Hope that this helps
EvScott
|
|
|
|
|
EvScott wrote: Compiler Warning (level 1) C4005
'identifier' : macro redefinition
The given identifier was defined twice. The compiler used the second macro definition.
Sudeep, observe the above which is an excerpt from MSDN. Make sure that you have only ONE identifer named "IDC_SIZE". The compiler will complain otherwise. Hope that this helps
idc_size is defined using #define only once. pls tell me where else can this declaration be found? i tried but cudn't get the solution
Thanks
|
|
|
|
|
Hi sudeep_br,
I suggestion that you change IDC_SIZE to exmaple IDC_SIZE2
and run again?whats happen?
-- modified at 2:10 Monday 10th April, 2006
and
m_yourButton.EnableWindow(0)
|
|
|
|
|
|
BOOL ProjectName::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem( IDC_Button )->EnableWindow(FALSE);´
}
|
|
|
|
|
sheshidar wrote: BOOL ProjectName::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem( IDC_Button )->EnableWindow(FALSE);´
}
Thanks for ur response. when i entered the above code i got a warning
"warning C4005: 'IDC_SIZE' : macro redefinition
see previous definition of 'IDC_SIZE'"
Please tell me what is wrong .where shud i make changes
sudeep
|
|
|
|
|
The easiest way is to check the "Disabled" box in the resouce editor.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thought I had this done, realised I would be sending strings as well and have had major trouble making it happen. I am trying to use a DLL I wrote in VC6 to send a string, via callback, to a VB app I wrote in VB6. Below is the code I am using on both the DLL and VB projects.
DLL Side:
extern "C" void __stdcall stat( void (*cb) (char**) )
{
char* nrMsg = "This is a test!";
cb( &nrMsg );
}
VB Side:
Declare Sub stat Lib "mydll.dll" (ByVal funcptr As Long)
'
Sub CallbackFunction(ByRef numb As Long)
Form1.Label1.Caption = "Success: " + Str(numb)
End Sub
Output:
Success: 268486828
I know I have to convert it to BSTR Unicode, but do not know how or what includes are needed. Not exactly sure how to pull that data in on the VB side either. All information I have seen thus far was all theoretical, so an example would be great concerning both sides (i.e., DLL and VB sides). I will eventually need to pass around 12 strings and 12 integers at one time.
If you need more info, let me know. Thanks in advance
Best Regards
|
|
|
|
|
|
Hey, thanks a lot for showing me your guides. I never new that Japanese users could have problems with certain code, even though it works perfectly for English users. Also, never knew that strings in C are an array of chars. Good information, well written. Still I have questions and need some help building an example. Here is my effort, which doesn't work.
#include <atlconv.h>
void Baz ( BSTR* pbstr );
extern "C" void __stdcall stat( void (*cb) (char**) )
{
using std::string;
USES_CONVERSION;
LPCWSTR wsz = L"Test this is.";
BSTR bs1;
bs2.Attach ( W2BSTR(wsz) );
cb ( bs1 );
SysFreeString ( bs1 );
}
I think I am just confused, because here is the compile errors and warnings:
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(48) : error C2065: '_ASSERTE' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2065: 'LPCOLESTR' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2146: syntax error : missing ')' before identifier 'x'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2433: 'ocslen' : 'inline' not permitted on data declarations
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2143: syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(122) : error C2447: missing function header (old-style formal list?)
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2143: syntax error : missing ';' before '*'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2433: 'OLECHAR' : 'inline' not permitted on data declarations
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2501: 'OLECHAR' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2061: syntax error : identifier 'LPOLESTR'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2501: 'ocscpy' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2065: 'dest' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : error C2065: 'src' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(123) : warning C4508: 'ocscpy' : function should return a value; 'void' return type assumed
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2143: syntax error : missing ';' before '*'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2433: 'OLECHAR' : 'inline' not permitted on data declarations
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2501: 'OLECHAR' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2086: 'OLECHAR' : redefinition
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2061: syntax error : identifier 'LPOLESTR'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : error C2501: 'ocscat' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(124) : warning C4508: 'ocscat' : function should return a value; 'void' return type assumed
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2146: syntax error : missing ';' before identifier 'T2COLE'
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2433: 'LPCOLESTR' : 'inline' not permitted on data declarations
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2501: 'LPCOLESTR' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Could someone take a look at what I have and show me what I have done wrong? I really need an example, never been a good non-hands-on learner. Thanks in advance.
best regards
-- modified at 22:03 Saturday 8th April, 2006
EDIT: Fixed to show include.
|
|
|
|
|
Your code sample doesn't make sense, but it looks like you're not using BSTR correctly. You also appear to not have the ATL or OLE headers included, so that's giving you the majority of the compiler errors. Start simple:
BSTR bs = SysAllocString ( L"Hello Bob" );
SysFreeString ( bs );
bs = NULL;
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I used #include <atlconv.h>.. was that not right? What is the name of the includes I need?
thanks in advance.
-- modified at 1:21 Sunday 9th April, 2006
EDIT: I took another look at the second guide and figured out what I needed to do. Thanks a lot for the all the help. This is solved.
best regards
|
|
|
|
|
Hi borono,
Still having problems? Have a look here[^]. This function will allow you to convert a char* which is a C string to a BSTR.
Maybe there are better methods of doing this from VB though.
|
|
|
|
|
I believe I have found the answer you are looking for right here[^]. Now if you don't have this up and working by the end of the day I am personaly going to come and steal your computer
|
|
|
|
|
haha, no worries. I do have it working, here is what I did.
DLL Side:
#include <comdef.h>
template< class T >
BSTR ToBSTR( T a_Str )
{
return( _bstr_t(a_Str).copy() ) ;
}
extern "C" void __stdcall stat( void (*cb) (u_short**) )
{
char dao[100];
sprintf(dao,"UDP: %d",udp);
BSTR l_Temp = ToBSTR(dao);
BSTR bs = SysAllocString ( l_Temp );
cb( &bs );
SysFreeString ( bs );
bs = NULL;
}
VB Side:
Declare Sub stat Lib "mydll.dll" (ByVal funcptr As Long)
'
Sub CallbackFunction(ByRef numb As String)
Form1.Label1.Caption = numb
End Sub
works great! computer saved.
best regards
-- modified at 10:37 Sunday 9th April, 2006
EDIT: thought it would be a good idea to include the conversion function, considering without it, this code is useless. Bold represents the modificiation.
|
|
|
|
|
borono wrote: haha, no worries. I do have it working,
Damnit, I just put my shoes on too. Congrats, you spent long enough on this, now you can move onto the next problem :P
|
|
|
|
|
haha, how'd you know I'd be having a problem? I am, but it is all design. This I really am horrible with. When it comes to design, you will see many programmers all designing their GUIs pretty much the same way. Not because there is a lack of creativity but because it works. There is indeed, at least, three ways to accomplish anything. They have found the first, I am concerned with the latter.
best regards
|
|
|
|
|
Hello!
In my program I have something like this:
<br />
volatile stop;<br />
<br />
void SetStop()<br />
{<br />
stop = true;<br />
while (stop) Sleep(100);<br />
}<br />
<br />
while (true)<br />
{<br />
if (stop) <br />
{<br />
stop = false;<br />
return;<br />
}<br />
Sleep(10);<br />
}<br />
But while the main thread waits for the
variable stop to be reset, this never
happens! Why not?
If I don't wait for it, the program opens
a message box (which sais that the thread
was not stopped; by use of a CSingleLock),
and when it is open, the thread resumes...
Alex
|
|
|
|
|
|
You forgot the variable type, bool is ok. So add bool after volatile;
volatile bool stop;
|
|
|
|
|
Thank you for your answer.
I only forgot it in my question, that's not the problem.
I also used the Debugger to go through the code.
But when I use "Run to Cursor" within the Thread-Loop
or set an breakpoint when I entered the waiting loop,
it never gets called.
Alex
|
|
|
|
|
I'm doing a hands-on learning process to communicate with a USB-GPS unit (specifically a Garmin GPS-18USB). I've searched a number of sources including Garmin's "SDK", and have figured out how to talk the language. I can manually get PVT info from the unit, etc., but would now like to move to the next step, that is, to make an MFC-based program "drive" the unit and display the data. The unit outputs data every second when instructed to do so.
I open the channel with CreateFile to produce a handle, and DeviceIoControl. I can send commands to the unit and receive data back. But I don't understand how to deal with asynchronous data and leave the GUI operating normally, that is, if I'm unsure when/if data may be received, I can't just call a Read or DeviceIoControl function: it will never return if there's no data available. I believe I need a worker thread to gather the data, but therein lies a problem:
How does one determine if data is available for a Read operation, read it, then get it back to the main app periodically for display? What's the right technique for managing this, knowing that perhaps the application may be asked to stop or close during a period that a Read operation is awaiting input? What functions may be used to allow a thread to be non-blocking, to respond to other messages?
|
|
|
|
|
Have a look at overlapped i/o (the last param in createfile , readfile etc).
You can then wait on events (read happened, thread should die, etc) in your worker thread.
Them when something interesting has been sent by the GPS unit, you can assemble it in your thread, and use PostMessage to kick your UI thread...
I know that's a short version....
Iain.
|
|
|
|
|
Thanks,
I've already tried the overlapped IO, so I guess I should use WaitForMultipleObjects: 1. the read complete and 2. the thread ends, etc.? I'm thinking that just waiting for a single object (the read happened) would still hang up?? Or will WaitForSingleObject@0mS in some kind of loop work?
|
|
|
|