|
can anyone tell me what this code do?
Please,
i what to know whats going on here thanks.
specially, inside of for loop.
thanks
bool CheckBoard( int board[9][9] ){
int i, j;
for( i = 0 ; i < 3 ; i++ ){// check small box
for( j = 0 ; j < 3 ; j++ ){
int r = 0;
r |= 1 << board[i*3 + 0][j*3 + 0];
r |= 1 << board[i*3 + 0][j*3 + 1];
r |= 1 << board[i*3 + 0][j*3 + 2];
r |= 1 << board[i*3 + 1][j*3 + 0];
r |= 1 << board[i*3 + 1][j*3 + 1];
r |= 1 << board[i*3 + 1][j*3 + 2];
r |= 1 << board[i*3 + 2][j*3 + 0];
r |= 1 << board[i*3 + 2][j*3 + 1];
r |= 1 << board[i*3 + 2][j*3 + 2];
if( r != 0x3fe )
return false;
}
}
for( i = 0 ; i < 9 ; i++ ){// check row
int r = 0;
for( j = 0 ; j < 9 ; j++ )
r |= 1 << board[i][j];
if( r != 0x3fe )
return false;
}
for( j = 0 ; j < 9 ; j++ ){ // check column
int r = 0;
for( i = 0 ; i < 9 ; i++ )
r |= 1 << board[i][j];
if( r != 0x3fe )
return false;
}
return true;
}
Junon
|
|
|
|
|
|
Hey come on, i'm not good at codeing, and using this board. sorry~~
anyway, this is part of the sudoku solving C++ program, and this is using,
#include iostream
#include cstring
using namespace std;
there is no class.
and just help with one for loop lest of others are same. give me some help.
thanks again.
Junon
-- modified at 12:24 Monday 8th May, 2006
|
|
|
|
|
for( i = 0 ; i < 9 ; i++ )
r |= 1 << board[i][j];
That loop starts with the variable 'r' equal to Zero and in each iteration of the loop it bitwise OR's r value with 0x00000001 shifted left 'n' bits where the value of 'n' is the value of the element at board[i][j].
I hope that helps.
Now please read the first message in the forum which tells you that this forum is for managed C++ / CLI issues which this is not. You need to move this thread to the C++ forum.
Good luck
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Hi Every one,
I'm programming in VC++ and I created a dll(MFC dll) with VC++,in this dll I'd like to have a function that export to out,I can do it ,but when I declare DllRegisterServer function I can't export it.
My code is same as folowing code:
__declspec(dllexport) STDAPI DllRegisterServer(void);
how can I export DllRegisterServer or DllUnregisterServer function that implemented in a dll ?
Please help me.
Best Regards.
Orchid
|
|
|
|
|
What is the error you get?
gmileka
|
|
|
|
|
I didn't get any error.my dll is compiled and its buid is succeeded but after that I open my dll with "DLL Export Viewer" software,I see all of functions in my dll is exported except DllUnregisterServer and DllregisterServer .
The code in my dll is same as this:
In header file I wrote (for example in Myheader.h)
__declspec(dllexport) STDAPI DllUnregisterServer(void);
In Source file I wrote (for example in Mysource.cpp):
STDAPI DllUnregisterServer(void)
{
};
I build this dll and every thing is ok but I get two warning they are same as these :
1-warning C4518: '__declspec(dllexport)' : storage-class or type specifier(s) unexpected here; ignored
2-warning C4502: 'linkage specification' requires use of keyword 'extern' and must precede all other specifiers
Both of them is happend in this line "__declspec(dllexport) STDAPI DllUnregisterServer(void);"
After that I check and open my dll with "DLL Export Viewer" software and I see DllUnregisterServer function isn't exported .I think mistake is in header file not in source file .If I write "STDAPI" before the "__declspec(dllexport)" in Myheader.h I get this error :
"error C2059: syntax error : '__declspec(dllexport)'
I can't find my mistake,if you have any idea I glad to hear it.
Best Regards.
Orchid
|
|
|
|
|
STDAPI resolves to EXTERN_C HRESULT STDAPICALLTYPE
So, both STDAPI __declspec(dllexport) and __declspec(dllexport) ATDAPI won't work because of the order of individual pieces when mixed with __declspec.
The following seems to work and achieves the same result:
Header:
extern "C" __declspec(dllexport) HRESULT __stdcall MyFunc(void);
CPP:
HRESULT __stdcall MyFunc(void);
{
}
If I do a "dumpbin /exports dllname.dll", I get _MyFunc.
gmileka
|
|
|
|
|
Thanks alot for your answer ,I wrote my code same as you mentioned ,my code is :
Header:
extern "C" __declspec(dllexport) HRESULT __stdcall DllRegisterServer(void);
CPP:
HRESULT __stdcall DllRegisterServer(void)
{
}
but when I compile and build it I get this error:
error C2375: 'DllRegisterServer' : redefinition; different linkage
I don't know what is its reason.
I'm appreciated for your help.
Best Regards.
Orchid
|
|
|
|
|
Based on:
http://msdn2.microsoft.com/en-US/library/5k6kw95a.aspx[^]
You will get this error if the prototype is defined twice with different linkage...
In otherword, some already defines DllRegissterServer(void) before you header definition...
To find it, you could add the compiler switch /P to the CPP including the header file. Then, right-click on the file and select 'compile'. This will output a file to disk that has all the included file and the line numbers... You can then search it for DllRegisterServer and figure out where it's coming from.
Remember to remove the /P switch before building your project.
I'm not sure what type of MFC dll you're using - but the other definition is coming from MFC most likely...
gmileka
|
|
|
|
|
I'm curious how the MFC dll was created through the Wizard... and which VS is being used. Since this is a C++/CLI forum, I would expect some interaction between the 'managed' MFC stuff and your declaration.
gmileka
|
|
|
|
|
I am attempting to write to a special serial device that requires one I/O to be sent for both reads and writes. The device receives a packet of information, like what would be sent on a WriteFile, and then expects to fill in a packet of data and return it like ReadFile.
Neither readfile or writefile will work, since write only sends packets and reads only retrieve them. The device will not operate with two IOs, as in a writefile/readfile sequence.
Does anyone know of an API call I can make to accomplish this? DeviceIOControl allows for both input and output packets, but I cannot find an IOCTL that implies it will do this.
Any help would be appreciated.
Thanks
Bill
|
|
|
|
|
What excatly u meant by "The device will not operate with two IOs"?
As long you opened the port and u have a valid handle to the port, you can write into it using WriteFile and read from using ReadFile.
Call WriteFile by passing the packet record expected by the device to OUT to the device.
Then Keep polling the port for an IN using ReadFile until u get the input or a predefined timeout expires.
Or else you can put a Sleep(100) immediatly after WriteFile and then try ReadFile.
Generally this is how RS232 works.
cheers...milton.
|
|
|
|
|
I have the following code, and I want to pass the variable test1 into the form, so that the form can read my test1 value. The var will be passed to SetParameter, a method under Form1. But I've encounted the following problem:
error C2664: 'void System::Windows::Forms::TextBox::set_Text(System::String __gc *)' : cannot convert parameter 1 from 'int' to 'System::String __gc *'
error C2039: 'SetParameter' : is not a member of 'System::Windows::Forms::Form'
Form1.cpp main:
int APIENTRY _tWinMain(HINSTANCE hInstance,<br />
HINSTANCE hPrevInstance,<br />
LPTSTR lpCmdLine,<br />
int nCmdShow)<br />
{<br />
int test1;<br />
string line;<br />
System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA;<br />
ifstream iFile("test.txt");<br />
<br />
if (!iFile)<br />
{<br />
return -1;<br />
}<br />
<br />
iFile >> test1;<br />
<br />
iFile.close();<br />
<br />
Form *Form1 = new Form();<br />
<br />
Form1->SetParameter(test1);
<br />
Application::Run(Form1);
return 0;<br />
}
Form1.h:
public __gc class Form1 : public System::Windows::Forms::Form<br />
{ <br />
public:<br />
Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
void SetParameter(int t){<br />
textBox1->Text = t;<br />
}<br />
<br />
protected:<br />
void Dispose(Boolean disposing)......<br />
.....<br />
.....<br />
.....
Actually I dunno where should I put the SetParameter, and how to convert int "t" to __gc textbox text as shown in the method.(since compiling the method results the first error)
Million thanks again.
|
|
|
|
|
You need to convert the 'int i' to a C string. You could use itoa() or printf(). Make sure the buffer is large enough to hold the resulting string.
Once you have a C string, convert it to a 'System::String'. You don't need to convert it to __gc textbox because you're assigning it to the 'Text' property of the text box... The property expects a string.
gmileka
|
|
|
|
|
hello
everythings gos good with the code Below, but when i try to make object (MessageQueue TheQueue = new MessageQueue;), it give me an errors says :
Error 1 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 2 error C3624: 'System::ComponentModel::Component': use of this type requires a reference to assembly 'System' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 3 error C3821: 'System::Messaging::MessageQueue': managed type or function cannot be used in an unmanaged function c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 4 error C2750: 'System::Messaging::MessageQueue' : cannot use 'new' on the reference type; use 'gcnew' instead c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 5 error C3642: 'System::Messaging::MessageQueue::MessageQueue(void)' : cannot call a function with __clrcall calling convention from native code c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 6 error C3175: 'System::Messaging::MessageQueue::MessageQueue' : cannot call a method of a managed type from unmanaged function 'SendToQueue' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
Error 7 error C2664: 'System::Messaging::MessageQueue::MessageQueue(System::String ^)' : cannot convert parameter 1 from 'System::Messaging::MessageQueue *' to 'System::String ^' c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\dll_from2005\MessageQueue\MessageQueue\MessageQueue.cpp 26
------------------------------------------------------
------------------------------------------------------
<br />
#include "stdafx.h"<br />
#using <system.messaging.dll><br />
using namespace System::Messaging;<br />
<br />
#ifdef _MANAGED<br />
#pragma managed(push, off)<br />
#endif<br />
<br />
BOOL APIENTRY DllMain( HMODULE hModule,<br />
DWORD ul_reason_for_call,<br />
LPVOID lpReserved<br />
)<br />
{<br />
return TRUE;<br />
}<br />
<br />
int _stdcall Sum(int inA, int inB) {<br />
return (inA + inB);<br />
}<br />
<br />
int _stdcall SendToQueue(char * SBody,char * SLabel)<br />
{<br />
MessageQueue TheQueue = new MessageQueue;<br />
return 0;<br />
}<br />
<br />
#ifdef _MANAGED<br />
#pragma managed(pop)<br />
#endif<br />
|
|
|
|
|
Here agin u chose an an unmanged project type insted of a managed one. Hope my reply to ur post below will make things clear.
rgds...milton
|
|
|
|
|
You've told the compiler that SendToQueue() is unmanaged, yet you're trying to use managed code in it.
And it should be
MessageQueue^ theQueue = gcnew MessageQueue;
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
nothing changes still have errors when i place MessageQueue^ theQueue = gcnew MessageQueue;
inside my function SendToQueue()
|
|
|
|
|
|
Yes, exactly .. he was trying to call managed code from unmanaged function. He got fixed creating a new managed cpp project.
rgds...milton
|
|
|
|
|
ALQallaf wrote: MessageQueue TheQueue = new MessageQueue;
As Mike said, you need to use gcnew and not new . Alternatively you can use stack semantics.
MessageQueue TheQueue;
TheQueue.Func(...);
Regards,
Nish
|
|
|
|
|
i tryed your syntax , but still having an errors nothing changed
|
|
|
|
|
ALQallaf wrote: i tryed your syntax , but still having an errors nothing changed
Check the following :
- Are you using the old syntax? You cannot use C++/CLI with the old syntax mode.
- Have you included references to all required assemblies?
- Are you inside a #pragma unmanaged block? If so, you cannot (obviously) do managed stuff in there.
Regards,
Nish
|
|
|
|
|
Thanks Nishant Sivakumar its works now
|
|
|
|