|
LongFangFang wrote: How to call a static libray in a dll? What exactly are you trying to do?
|
|
|
|
|
I have a third party unmanaged c++ library.
I created a managed c++ wrapper for it since I need to call it from c# code. Problem is one of native c++ functions passes an int by reference. I do not know how to route this through the managed wrapper to the c# code. For example
class A //unmnaged SDK class
{
public:
void Foo(int& i);
}
//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int& i) { _unmanaged->Foo(i)};
private:
A * _unmanaged;
}
In my c# (yes #) code I try to call A_Wrapper::Foo() but I get compile errors
c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(&id);
}
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
I don't really want to wrap it in an unsafe {} block. How do I route the pass by reference from c++ to c# properly?
Update: Answered. (I figured it out) I had to change the wrapper class to use tracking references, i.e.
//managed c++ wrapper
public ref class A_Wrapper
{
public:
A_Wrapper() {_unmanaged = new A();};
~A_Wrapper() {delete unmanaged; };
void Foo(int% i)
{
int ret=0;
_unmanaged->Foo(ret);
i = ret;
};
private:
A * _unmanaged;
}
c# code:
public static void Main()
{
A_Wrapper aw = new A_Wrapper();
int id = 0;
aw.Foo(ref id);
}
|
|
|
|
|
Four programs (listings 19.4, 19.5, 19.6 and 19.7) in the book
"Teach Yourself C++ in 21 Days" by Jesse Liberty and Bradley Jones
do not compile. The first of these programs is as follows:
//Listing 19.4 Using Operator ostream
#include <iostream>
using namespace std;
const int DefaultSize = 10;
class Animal
{
public:
Animal(int);
Animal();
~Animal() {}
int GetWeight() const { return itsWeight; }
void Display() const { cout << itsWeight; }
private:
int itsWeight;
};
Animal::Animal(int weight):
itsWeight(weight)
{}
Animal::Animal():
itsWeight(0)
{}
template <class T> // declare the template and the parameter
class Array // the class being parameterized
{
public:
// constructors
Array(int itsSize = DefaultSize);
Array(const Array &rhs);
~Array() { delete [] pType; }
// operators
Array& operator=(const Array&);
T& operator[](int offSet) { return pType[offSet]; }
const T& operator[](int offSet) const
{ return pType[offSet]; }
// accessors
int GetSize() const { return itsSize; }
// template <class T>
friend ostream& operator<< (ostream&, Array<T>&);
private:
T *pType;
int itsSize;
};
template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
for (int i = 0; i < theArray.itsSize; i++)
{
output << "[" << i << "] " << theArray[i] << endl;
}
return output;
}
// implementations follow...
// implement the Constructor
template <class T>
Array<T>::Array(int size):
itsSize(size)
{
pType = new T[size];
for (int i = 0; i < size; i++)
pType[i] = 0;
}
// copy constructor
template <class T>
Array<T>::Array(const Array &rhs)
{
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
}
// operator=
template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
if (this == &rhs)
return *this;
delete [] pType;
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i = 0; i < itsSize; i++)
pType[i] = rhs[i];
return *this;
}
int main()
{
bool Stop = false; // flag for looping
int offset, value;<pre lang="c++"></pre>
Array<int> theArray;
while (Stop == false)
{
cout << "Enter an offset (0-9) ";
cout << "and a value. (-1 to stop): ";
cin >> offset >> value;
if (offset < 0)
break;
if (offset > 9)
{
cout << "***Please use values between 0 and 9.***\n";
continue;
}
theArray[offset] = value;
}
cout << endl << "Here's the entire array:" << endl;
cout << theArray << endl;
return 0;
}
Attempting to compile this program on Linux with g++ produces the
following message:
g++ -fpermissive list1904.cpp -o List19.4
list1904.cpp:45:52: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, Array<T>&)’ declares a non-template function [-Wnon-template-friend]
list1904.cpp:45:52: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
/tmp/ccgXupn5.o: In function `main':
list1904.cpp text+0x102): undefined reference to `operator<<(std::ostream&, Array<int>&)'
collect2: error: ld returned 1 exit status
make: *** [List19.4] Error 1
I would very much appreciate any help in resolving this problem.
Thank you very much,
tim_mann
tcnm
-- modified 14-Dec-12 16:09pm.
|
|
|
|
|
Unfortunatel, since you did not format your code block properly (i.e. between <pre> tags) there are some bits missing, so I cannot compile what you have here. Please edit your message add the tags, and format the code, so it shows like :
#include <iostream>
using namespace std;
void ShowError(DWORD dwError)
{
wcout << "Error code: " << dwError << " << endl;
}
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I did not realize that, when I copied the code onto this forum. everything disappeared when the signs < > appeared. Thus, #include <iostream> appeared only as #include, and <T> or <int> never appeared. I'm trying to find out how to edit the posting.
tcnm
P.S. Apparently this problem occurred because I had not checked the "Treat my content as plain text not as HTML" button. I have now corrected this situation. The listed program is now complete as it appears in the book.
-- modified 14-Dec-12 16:15pm.
|
|
|
|
|
You still have not used <pre> tags around your code, as I suggested in my original question to you.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Why c is so important? How to manage it in linux?
|
|
|
|
|
riceshoots wrote: Why c is so important? Important in what sense?
riceshoots wrote: How to manage it in linux? What do you mean? If you are asking how to run managed code on Linux then you need to investigate the use of Mono[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
With VS 2012, MS has officially documented how to create native debug visualizers by creating a .natvis file.
Unfortunately, they do not work when you debug in Mixed mode even when you're debugging Native code.
I'd love it if you could upvote my co-worker's Connect issue for this.
Debug Visualizers in mixed mode apps have regressed
We got Intellisense back for C++/CLI, let's shoot for the moon and try for debug visualizer support.
Thanks for your time if you do vote!
John
|
|
|
|
|
Visual Studio C++ provides facility for using ActiveX control in VC6.0 as well as in VC2010. I tried NTGraph3D activeX Control in VC6.0. It is working perfectly.
I tried the same in VC 2010. So for Visual Studio 2010, NTGraph3D ActiveX Control is not working.
So can anyone help me to solve this problem. Is there any change in properties ?
|
|
|
|
|
|
Hi,
We are seeing some strange behavior with our applications recently.
We have developed a VC++ application (dll) which will be loaded by another application (exe, core product). The dll is developed in VC++ 2005 with MFC.
When we open any dialog from the exe, we could see some junk character (luckily 'J' all the time) populated in all the empty fields on the dialog.
Customer is very annoyed with this behavior but we could not figure out the solution. They are saying the issue is caused by the dll.
Hope someone will help me.
|
|
|
|
|
Hi,
I want to get a dll's version detail ,which is registered.
And want to get this data programmetically.
I think ,One way we can make our code to search in Registry-entries & get the information from there.
But unfortunately, i'm not fully aware, what will be the code for this.
PLease advice
|
|
|
|
|
Why have you posted this question here? It has nothing to do with C++/CLI, and I have already answered it in this thread[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi Richard,
It's related to C++ ,I thought we can put here
|
|
|
|
|
This forum is for C++/CLI issues.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I don't disagree with your chiding but you answered a different question in that message. He was looking for info on how to get the DLL version info here. The question/answer you refer to in the other thread was how to get the DLL file location...
... both worthy questions but, yeah, should have been asked in a different forum.
--
Harvey
|
|
|
|
|
Since this question is nearly two months old your comments and answer are largely irrelevant.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Perhaps for the original author but not for someone reading the thread who might be looking for the answer to the question.
--
Harvey
|
|
|
|
|
I think you are looking for the DLLVERSIONINFO data. Here is a class that loads a dll and pulls that info from it:
class CLoadLibrary
{
public:
CLoadLibrary(LPCTSTR lpszLibFileName);
virtual ~CLoadLibrary();
operator HINSTANCE();
DWORD GetModuleVersion();
protected:
HINSTANCE m_hLibModule;
};
CLoadLibrary::CLoadLibrary(LPCTSTR lpszLibFileName)
{
m_hLibModule = ::LoadLibrary(lpszLibFileName);
ASSERT(m_hLibModule != NULL);
}
CLoadLibrary::~CLoadLibrary()
{
::FreeLibrary(m_hLibModule);
}
CLoadLibrary::operator HINSTANCE()
{
return m_hLibModule;
}
DWORD CLoadLibrary::GetModuleVersion()
{
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO*);
DLLGETVERSIONPROC pDllGetVersion =
(DLLGETVERSIONPROC)::GetProcAddress(*this, _T("DllGetVersion"));
DWORD dwVersion = 0L;
if (pDllGetVersion != NULL)
{
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
HRESULT hr = (*pDllGetVersion)(&dvi);
if (SUCCEEDED(hr))
{
ASSERT(dvi.dwMajorVersion <= 0xFFFF);
ASSERT(dvi.dwMinorVersion <= 0xFFFF);
dwVersion = MAKELONG(dvi.dwMinorVersion, dvi.dwMajorVersion);
}
}
return dwVersion;
}
Clearly you can simplify it for your needs...
--
Harvey
|
|
|
|
|
Here is the MSDN information for Threadpool of I/O Completion Objects. http://msdn.microsoft.com/en-us/library/windows/desktop/ms682464(v=vs.85).aspx
But I can not use them to create my threadpool and do asyn read and write operation.Is anyone have experience of using these functions?
CancelThreadpoolIo CloseThreadpoolIo StartThreadpoolIo Thread Pools WaitForThreadpoolIoCallbacks
Would you give me a code example for these use?
Thank you!
I/O Completion, Threadpool
|
|
|
|
|
Any C++/CLI Experts wanted to become book author?
Please do contact author@darkcrab.com,
Darkcrab Press new book publishing company offering opportunity for fresh authors. Grab this opportunity and become an author soon. All the best friends.
|
|
|
|
|
Hi All,
Convert 24-bit bmp capture to 8-bit capture in VC++, is it possible?
Possible,
Can any provide the solution.
Thanks,
Lucky.
|
|
|
|
|
lucky_1221 wrote: is it possible?
Yes.
lucky_1221 wrote: Can any provide the solution.
Presumably you want someone to give you the code rather than just wanting to know if anyone could figure it out.
I won't be providing the code.
Presuming that no one else will either then you would need to do the following.
1. Learn basic programming
2. Learn basic IO (presumably you want to do this to files.)
3. Learn what image formats exists, and find the specifications for each. This includes 24 bit and 8 bit.
4. Write code to read a 24 bit image - using 1/3
5. Write code to write a 8 bit image - using 1/3
6. Put 2, 4 and 5 together into a program.
|
|
|
|
|
Hi All,
Currently i am able to capture the 24-bit screens capturerin.
at the same process i am unable to capture the 8-bit screens and 16-bit screens.
Can any one have this solution provide please.
Thanks,
lucky.
|
|
|
|