|
|
Ah - so it's a C++/CLI issue - well, that ain't going to worry me - I use vanilla C++
But anyway - it only affects you (IIUC) when you statically link against Boost.Threads. If you put this line before any Boost #includes, then Boost will automatically link against the DLL.
#define BOOST_THREAD_DYN_DLL
I've just tested this with a little sample program (built with VC2008) which had this code compiled with /clr:
#include "stdafx.h"
using namespace System;
extern void flibble();
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
flibble();
return 0;
}
and this code compiled as native (against Boost 1.37.0)
#define BOOST_THREAD_DYN_DLL
#include <boost/thread.hpp>
void ThreadFunc()
{
for(int i=0;i<INT_MAX;++i)
;
}
void flibble()
{
boost::thread t(&ThreadFunc);
t.join();
}
It ran successfully, but if I removed or commented out the #define , it crashed on start-up. So - there was probably no need to dump Boost
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Oh great. I am gonna test this out tommorow.
But the CLI portion of my project is Dynamic Library type with MFC in a Shared DLL.
I am not sure what my C# Project type is.
When you say But anyway - it only affects you (IIUC) when you statically link against Boost.Threads. If you put this line before any Boost #includes, then Boost will automatically link against the DLL.
1) what do you actually mean? Would you be able to make the meaning clearer?
2) Why is Boost statically linking with my library? or is vice versa? what does that actually mean?
3) What is difference between static and dynamic linkage.
It would be really great if you could answer these questions.
|
|
|
|
|
jobin007007 wrote: 3) What is difference between static and dynamic linkage.
Static linking = link against a .lib containing object file - the object files are incorporated into your .exe or .dll
Dynamic linking = link against a .lib that references a DLL - your .exe or .dll will call the DLL when it calls the functions from the library.
jobin007007 wrote: 1) what do you actually mean? Would you be able to make the meaning clearer?
Boost (on Windows) has this really cool mechanism which automatically specifies which Boost libraries the linker should use when making your .exe or .dll. This takes into account various factors like a) what compiler you're using, b) (for Visual C++) what C run-time you're using, c) whether you're building a Debug or Release build. The one thing you have control over is whether a dynamic or static version of the Boost library is used. By using the line I gave you, you are telling Boost that you want to use the DLL version of Boost.Threads, not the other one. Boost will then tell the linker to use the DLL version of Boost.Threads.
jobin007007 wrote: 2) Why is Boost statically linking with my library? or is vice versa? what does that actually mean?
Your library is statically linking the Boost library. This happens because by default, Boost libraries automatically get statically linked.
HTH!!!
jobin007007 wrote: I am not sure what my C# Project type is.
That doesn't matter.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Would you able to tell me how to adapt my code to the code you wrote earlier?
Class ABC
{
int a;
int b;
void DO()
{
this.a="";
this.b="";
this.capture();
}
void capture()
{
}
};
void main()
{
ABC Object[20];
for(int i=0;i<20;i++)
createthread(Object[i].DO); //So 20 Threads are created here.
}
I am unsure as of how to use your example in my code.
|
|
|
|
|
There are so many ways...here's one
void MyThreadProc(void* objectAsVoidPtr)
{
ABC* object = (ABC*)objectAsVoidPtr;
object->DO();
}
void main()
{
ABC Object[20];
for(int i=0;i<20;i++)
_beginthread(MyThreadProc, 0, (LPVOID)Object+i);
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
#include iostream; //can't paste the << >> things here
#include string;
int main()
{
//works, from what i can see, because you cant compile "int someArray[] = {}" or "int arr[0];" because you cant allocate a 0-length array according to vs.net errors. So your guarenteed atleast 1 item in the array for "sizeof(_array[0])" to always find an item. this is the alternative to doing sizeof(int) or passing the type of the array to the macro.
#define ARRAY_LENGTH(_array) (sizeof(_array)/sizeof(_array[0]))
int someArray[] = {1, 2, 3, 4};
for(int i = 0; i < ARRAY_LENGTH(someArray); i++)
{
std::cout<<*(someArray + i)<
|
|
|
|
|
ARRAY_LENGTH macro is always ok for real array but not for pointer.
By the way, ARRAYSIZE() macro is predefined in windows.h of some newer sdk and it looks the same form as above.
|
|
|
|
|
wow norish i had no idea about that macro :P when i read that sizeof returned the number of bytes used by an array, i figured if i just divided by the size of the datatype used that i could get the length.
|
|
|
|
|
If you want a type-safe mechanism for getting the number of elements in an array, you might consider this:
#include <iostream>
template<class A, size_t N>
inline size_t ArraySize(const A ( & )[N]) { return N; }
template <typename T>
struct array_info
{
};
template <typename T, size_t N>
struct array_info<T[N]>
{
typedef T type;
enum { size = N };
};
int main()
{
typedef int (MyArray)[120];
int a[120];
float b[120];
std::cout << ArraySize(a) << std::endl;
std::cout << ArraySize(b) << std::endl;
std::cout << array_info<MyArray>::size << std::endl;
}
Here you have mechanisms for getting the number of elements in an array variable (function ArraySize ) or an array type (struct array_info ). And (unlike the macro version) these two won't compile if given a pointer variable/type - the power of pattern matching sees to that
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
hmm vectors? i suppose. Is it possible that arrays are more efficient?
Now this part of the code is really sexy:
<br />
template<class A, size_t N><br />
inline size_t ArraySize(const A ( & )[N]) <br />
{ <br />
return N; <br />
}<br />
<br />
int main()<br />
{<br />
int a[120];<br />
<br />
std::cout << ArraySize(a) << std::endl;<br />
}<br />
i'm not sure how it works but my guess is that somehow it's magically reading the size from the declaration of the array.
|
|
|
|
|
FocusedWolf wrote: possible that arrays are more efficient
Nope - in VS2008, vectors are guaranteed to use contiguous storage (i.e. same as arrays).
FocusedWolf wrote: i'm not sure how it works but my guess is that somehow it's magically reading the size from the declaration of the array.
That's the one. You pass an array and the compiler instantiates the function with the template parameters appropriate for that array.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Not always necessarily better - not until C++ 0x when vectors get array style initialisers (IIU&RC).
Say I have an encryption key that (foolishly) I'm hardcoding in the software - which is simpler:
[edit]Or a better example - say I'm implementing a CRC32, which can be highly optimised by using a static array of byte values[/edit]
const BYTE key[] = { 12, 34, 4, 5, 36, 23, 765, 34 };
std::vector<BYTE> vKey;
vKey.push_back(12);
: :
vKey.push_back(34);
Yes, I know Boost has a library[^] that almost gives vectors initialiser syntax...but sometimes you just can't be bothered
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
FocusedWolf wrote: #include iostream; //can't paste the << >> things here
#include string;
Why not?
#include <iostream>
#include <string> Did you use the < button above the smileys?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hmm:
#include <iostream>
#include <string>
O i see... if this works then the lt,gt things are auto replacing my < >. Ya didn't realize that yesterday lol
|
|
|
|
|
see the _countof macro in the Run-Time Library Reference
|
|
|
|
|
Hi
How can I disable MDI to send a "File New" message at start up? So there will be no child window to be opened.
Best regards,
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i am devloping an gui i want to use the costum controls(like styleish buttons) available in net but don't know how to use the code in my project ..have tried a lot but failed pls help me out..
|
|
|
|
|
Are you possibly referring to a manifest?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Bisua wrote: costum controls(like styleish buttons)
On Halloween CodeProject sends out stylish costume controls for free!
Anyway, you should have a look at this section:
http://www.codeproject.com/KB/buttons/[^]
|
|
|
|
|
In VS 2005, When I do CView::OnFilePrintPreview, it loads up the printPreview into the frame, not into a View frame. If I close the print Preview(using the X close button), it just closes the frame window, which I don't wanna do. I would like to keep the frame window open when I close the print Preview. It didn't work this way in V6.0, Does any one know how can I fix this?
sft
|
|
|
|
|
I'm new in Visual C++
I've made an empty DIALOG where I load a floor layout (BMP resource) and then I draw on it a dot indicating my position (dot = dot.bmp as a resource as well)
I added a ZOOM button (boolean). If user presses it image would be zoomed-in tweaking STRECHTBLT
void CDisplayDlg::OnPaint()
{
HBITMAP hBmpL1=::LoadBitmap(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDB_DISPLAY_BITMAP));
CRect rc;
this->GetClientRect(&rc);
HDC hdc1 = ::GetDC(this->m_hWnd);
HDC hdcmem = ::CreateCompatibleDC(hdc1);
::SelectObject(hdcmem,hBmpL1);
if (zoom)
{
::StretchBlt(hdc1, 0,0, 364, 64, hdcmem,0,0, 620, 109,SRCCOPY);
}
else
{
::StretchBlt(hdc1, 0,0, 205, 37, hdcmem,0,0, 620, 109,SRCCOPY);
}
}
screencap: http://telefonica.net/web/episodio1/cap001.gif[^]
I dont know how to add horizontal scroll bar to my image when I zoom. If I add scrollbar to my whole dialog it doesn't do anything.
Thanks.
|
|
|
|