|
Without extern, every translation unit (cpp file) in which you included i gets its own i. That is, each translation unit reserves memory for the variable.
Did you try including thhe file in multiple cpp files? You'll find that the code won't link, you'll get linker errors complaining about multiple symbol redefinitions for i. The reason is the same, each cpp file has a global i, so the linker doesn't know which i to use.
The solution is to define the variable in one cpp file and to declare the variable extern in the header file. This way, all cpp files including the header files will recognize that variable is defined somewhere else.
Does this answer your question?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thank you..........
shamnar
|
|
|
|
|
Hi,
Iam trying to implement a cross-platform encryption system.
i.e, in windows i will encrypt a file and in Linux will try to decrypt it and viceversa. The same encryption algorithm can be used on both platforms.
NET has Cryptography namespace in which all this algo are implemented and API's available. But when we go in to linux , we cannot use this .NET API's. so, some libraries muist be available to implement this algo in both platforms.
I got some info on using OPENSSL libraries which i can use for implementing encryption algo. But some problems is ther when it comes to cross platform.
So, need some guidelines and ideas for this.
Please mail me if u had come across similar situation and help in the same.
Thanks.
Mani
|
|
|
|
|
Can u be more specific abt the problems u faced.
For cross platform code usability,the general practice is to make code in c/c++,STL. Then compile/link it on diffrent platforms which ever is required.
There are lots of free source code available on net which compiles with both Microssoft CL.exe and the unix/linux GCC.
cheers...milton.
|
|
|
|
|
What I need to do is this:
To take a structure (or a class that contains only variables) then convert it somehow to an array of bytes, so i will be able to send it with the Write function of the SerialPort Control.
On the other side of the port i need to do backward process
Can anyone help me with this one?
thanks
|
|
|
|
|
Call createfile to get a valid handle to the port:
hPort = CreateFile(lpszPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL,<br />
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |<br />
FILE_FLAG_OVERLAPPED, NULL);
Then set the device control block with appropriate baude rate and parity bit settings and other settings.
<br />
DCB dcb; <br />
dcb.DCBlength = sizeof( DCB ) ;<br />
GetCommState( ufp, &dcb ) ;<br />
dcb.BaudRate = baud;<br />
SetCommState(ufp, &dcb);
Now you can start writing to the device.
WriteFile(hPort, bfr2write, dwBytestoWrite, &dwBytesWritten, &OVERLAPPEDWrite);
To Readfrom the file:
ClearCommError( hPort, &dwErrorFlags, &ComStat ) ;
dwLength = min( (DWORD) MaxLength, ComStat.cbInQue );
if (dwLength > 0) {<br />
fReadStat = ReadFile( hPort, lpzBlock,
dwLength, &dwLength, &osRead ) ;<br />
if (!fReadStat) {<br />
Err("ReadSPort");<br />
dwLength = 0 ;<br />
ClearCommError( hPort, &dwErrorFlags, &ComStat ) ;<br />
}<br />
}
cheers...milton.
|
|
|
|
|
Thanks,
But in this way I don’t really use the SerialPort Control that .net 2 gave me.
Do u know how to do it with the SerialPort Control?
|
|
|
|
|
|
I am working to upgrade an application to manadeg code which has to use unmanaged DB functions and a large DB created with them.
I have been able to read the records sequentially, and lets say I have read a value of an existing record key field(long) and named it Currtmp, could anyone perhaps give me an opinion on my try (based on an earlier piece of advice by Milton KB)
String ^crpt = Currtmp.ToString();
pin_ptr<const void*=""> tnoptr = static_cast<marshal::stringtohglobalansi(crpt)>.ToPointer();
d:keyfind(..., tnoptr, ...);
In compiling I receive the error
error C2061: syntax error:identifier 'StringToHGlobalAnsi'
When editing the line of pin_ptr ..., the editor gives after the two colons as one alternative this 'StringToHGlobalAnsi',
but in compiling I get the above error. Is this completely wrong thinking.
When I move the mouse focus on the line to the point over the 'StringToHGlobalAnsi' a box appears containing
static System::IntPtr System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(System::String ^s)
copies the contents of managed System.String into unmanaged memory, converting into ANSI format as it copies
so at least the text would indicate that I could be on the right road, but ...
I have also tried several other identifiers instead of 'const void*', with similar results. The native code function needs the identifier (const void*).
Ilkka Pitkänen
|
|
|
|
|
I juz went thru my reply to your previous post.
There I suggested to use __gc char* and it was a .net 1.1 syntax. This might have failed for you if you are using .net 2.0.
But in your new code, you are using pin_ptr . This is not required if you are using StringToHGlobalAnsi . Because StringToHGlobalAnsi will allocate memory in the unmanaged heap and .Net GC can't do anything on this unamaged memory. So you dont have to pin it to prevent from memory relocation.
Try below coed. This works in 2.0 with /clr:pure
long Currtmp = 117;<br />
String ^crpt = Currtmp.ToString();<br />
IntPtr intptr = Marshal::StringToHGlobalAnsi(crpt);<br />
d:keyfind(..., intptr.ToPointer(), ...);<br />
Marshal::FreeHGlobal(intptr);
cheers...milton.
|
|
|
|
|
I have a native c++ class in a native code dll.
I wrapped it with a managed c++ class library in visual studio 2005 by:
1. Creating an instance to the native class in my constructor and deleting the instance in the destructor.
2. Implementing all of it's interface and calling each matching function.
I was able to compile the class library succesfully.
When attempting to use it in a CLR console application I Added a reference to it in the application.
The autocomplete recognizes the classes and recognizes the public functions of the classes.
My problem is that when I compile the program i get the following error:
error C3767: 'XP_Talk::XPMyClass::Init' candidate function(s) not accessible.
Why does this happen? XPMyClass::Init was declared public and is seen in autocomplete as public...
So why do i recieve this error and how do i resolve the problem?
|
|
|
|
|
Make sure ur managed cpp class declared with modifiers public ref and method has public modifieres.
namespace XP_Talk{<br />
public ref XPMyClass{<br />
<br />
public:<br />
<br />
void Init();<br />
<br />
}<br />
}
milton
|
|
|
|
|
Since you say that you declared the functions as public there is only one case which i ran into in which i recieved this error.
If one of the functions in the managed class library recieves an unmanaged type then verify that the native class you are wrapping (it's header) is declared as public.
//native class
#ifdef _MANAGED
public
#endif //!_MANAGED
class UNMANAGEDDLL_API CUnmanagedDll
{
public:
CUnmanagedDll(void)
{
}
double Add(double First,double Second)
{
return (First + Second);
}
// TODO: add your methods here.
};
In this case the function Add does not recieve an unmanaged type.
If it recieved an unmanaged object for instance than the public would be mandatory.
|
|
|
|
|
Hi ,
Can any one please let me know how can i use the vc++ code in c# using the concept of Managed and Unmanaged code?
Bcoz i dot have any idea about the interface so please suggest me about how i can go ahead.
Thanks
|
|
|
|
|
|
RajArchana wrote: Can any one please let me know how can i use the vc++ code in c# using the concept of Managed and Unmanaged code?
Bcoz i dot have any idea about the interface so please suggest me about how i can go ahead.
You can write a mixed-mode DLL (using C++/CLI) that will expose a managed interface that C# callers can use. You'd have to know C++/CLI syntax, and how to wrap native classes for consumption from managed callers. Check out the C++/CLI section on Code Project and MSDN for a bunch of articles on this topic.
Regards,
Nish
|
|
|
|
|
Hi all, have a nice day.
I want some graphic base codes, include DDA, Midpoint and Bresenham algorithm of line, circle, ellipse and parabola (3 x 4 = 12), fillcolor and clipping.
Would you like send me?
Thanks very much.
My email: duyviet2412@gmail.com
|
|
|
|
|
And this has what to do with "managed and mixed-mode C++ programming"?
"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
|
|
|
|
|
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
|
|
|
|