|
Hi,
An application written in C#-VS2005 needs to use a class exported in a VC6Dll.
I have googled around a bit about Data Marshalling using P/Invoke. But all I could find is information on how to use the exported functions from a dll OR a struct from a dll.
I could not find any info on how to use the (exported,unmanaged) class of the dll in my C# App.
Any help or link woud be helpful.
Thanks and Regards,
Arti Gujare
|
|
|
|
|
Don't cross post especially don't cross post into a C++ forum with a C# question.
led mike
|
|
|
|
|
Apologies.
This Mixed Mode coding makes me confused sometimes. :
|
|
|
|
|
Hi all...
I am working with visual studio 2005.In my application ,i need to transfer dataset content to local database table.I am using MS Access .Please help me...
Thanks
vinod
|
|
|
|
|
Have you looked at the scores of Database articles here on CodeProject?
led mike
|
|
|
|
|
When using a Managed C++ Wrapper to expose methods to C# and VB.NET I get cannot create reference to this object when I transfer my compiled application to another machine. I am using C# and VB.NET by making a reference to it, and (Using or Import...), I am able to compile on a machine using VS-2005 CLI C++ and make a DLL. On the same machine I can reference this DLL, and utilize its exposed methods. This works all the time on the same machine that I compiled the CLI C++ DLL on, but when I copy the C# or VB source code and DLL to another machine, I have to re-run the Managed C++ Compile from source code in order to properly reference the DLL. What am I missing if I want to compile and distribute my VB or C# Application with this DLL? What is the compiler doing that I am not when I reference the DLL? Should I attempt to Sign and import it into the GAC or? What is the proper way of performing this?
|
|
|
|
|
Your app probably requires the redistributable for C++, and you also need to make sure you distribute the manifest file
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Given a Borland OWL application, I am curious if it is possible to display C# dialogs. I know OWL will allow calls into MFC DLLs. And I have already done work in an MFC application to display C# dialogs.
So it seems reasonable for OWL to call the MFC DLL which will call the C# DLL.
I am wondering if it will require the MFC DLL to be a regular DLL (derived from CWinApp), or if an extension DLL will also work.
At this time, I do not actually have a Borland OWL application, otherwise I would just try it out for myself. I am curious for a future possibility requiring this ability. I was thinking the OWL application's menu item can call into the MFC DLL, which will be a pass through to a C# DLL(s) containing various C# dialogs.
Thanks for any insight and help.
|
|
|
|
|
|
Oops. Sorry. In the past (meaning several months ago), I've seen this board used for MFC->Managed and MFC->.NET questions, whereas the C# board has been more focused directly on C# questions.
|
|
|
|
|
hi friends
i am new in c++
I have one file enc.cpp
i dnt know how to run it.
plz tell me how to run project in c++ .net
thanks in advance.
khan
|
|
|
|
|
imrankhanpathan wrote: I have one file enc.cpp
And what does it contain ? I mean function,classes etc.
Every C++ app need to have an entry point function. main for console app. for instace.
Does your file contains such function ?
BTW, you need to ask this question in VC++ forum.
|
|
|
|
|
hi prasad
thanks ur reply
actually i download one project for encryption and has a many functions,one is entry point in enc.cpp.
so plz tell me now how to run it.
thanks again
khan
|
|
|
|
|
You need to include it in a project. And, as has been said, you're in the wrong forum.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
In C/C++ what r the differences between header file(.h)
& library files(.lib). Which of them contains function
Declaration and which contains Definition?
|
|
|
|
|
A header file contains source code. A lib file contains object code (already compiled).
By convention, header files contain declarations, inline definitions, and any other source code
that needs to be shared by multiple source files.
|
|
|
|
|
Hi all, i was curious to know how would i program a function to create a file into any directory. For example. Most windows dirs begin with c:\
But what if they have a custom dir? Like E:\ or H:\ ?
I would just like to know if i can make a function that will add a file in the folder no matter what the directory begins with. Thanx in advance!
|
|
|
|
|
You want to do this in managed C++, or are you in the wrong forum ?
You'd generally let the user choose the directory they wanted to create into, or you'd use the path to your executable as a starting point, if you wanted to create it locally.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all,
well allthough I'm new to C++ I've done my share of development in more user friendly environments, mainly C#.
Anyhow I want to learn C++ as mainly personal interest as my professional life will be focused primarly in .NET development whenever it is needed.
To learn the basics of the language I'm starting with a real easy Math class that will initially implement a Matrix (no templates). Nothing fancy but an easy place to start to at least start learning Object Oriented programming in C++ like any other.
Well the thing is that I'm completely stumped with an error I'm getting. I've created a simple Win32 console app that links my FastMath.dll and uses the FMatrix class defined inside. Test app code is as simple as it can get, it only instantiates one FMatrix and then deletes it, and something that simple is giving me a runtime error. Here's the code in the tesp app:
#include "stdafx.h"
#include "FMatrix.h"
#include <iostream>
using namespace FastMath;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
FMatrix *a=new FMatrix(5);
cout << "A is a [" << a->GetRowCount() << "x" << a->GetColumnCount() << "] matrix." << endl;
delete a;
return 0;
}
Ok the error I'm getting is when executing "delete a":
Windows has triggered a breakpoint in Tester.exe.
This may be due to a corruption of the heap, and indicates a bug in Tester.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
If I try to continue I get the same error once and then succesive Assertion Failed error messages: "Expression: _CrtIsValidHeapPointer(pUserData)" and if I ignore that I get a HEAP CORRUPTION DETECTED error message "CRT detected that the application wrote to memory after end of heap buffer."
I really do not understand what I'm doing wrong in my FMatrix file. I'm including header and source files below:
FMatrix.h
#ifdef FASTMATH_EXPORTS
#define FASTMATH_API __declspec(dllexport)
#else
#define FASTMATH_API __declspec(dllimport)
#endif
#pragma once
#include "StdAfx.h"
namespace FastMath
{
class FASTMATH_API FMatrix
{
private:
int rw,cl;
double *val;
FMatrix(void);
FMatrix(unsigned int,bool);
FMatrix(unsigned int,unsigned int,bool);
void initMatrix(unsigned int,unsigned int,bool);
void destroy(void);
public:
FMatrix(const FMatrix&);
FMatrix(unsigned int);
FMatrix(unsigned int,unsigned int);
FMatrix(unsigned int,unsigned int,double**);
~FMatrix(void);
static FMatrix* CreateIdentity(unsigned int);
static FMatrix* CreateFull(unsigned int,unsigned int,double);
static FMatrix* CreateRandomIntMatrix(unsigned int,unsigned int,int,int);
static FMatrix* CreateRandomDblMatrix(unsigned int,unsigned int,double,double);
double GetItem(unsigned int,unsigned int) const;
void SetItem(unsigned int,unsigned int,double);
int GetRowCount() const;
int GetColumnCount() const;
static bool AreSameSize(const FMatrix&,const FMatrix&);
FMatrix& operator =(const FMatrix&);
FMatrix& operator -() const;
FMatrix& operator +(const FMatrix&) const;
FMatrix& operator -(const FMatrix&) const;
FMatrix& operator *(double) const;
FMatrix& operator *(const FMatrix&) const;
FMatrix& operator !() const;
bool operator ==(const FMatrix&) const;
bool operator !=(const FMatrix&) const;
};
}
FMatrix.cpp
#include "StdAfx.h"
#include "FMatrix.h"
#include "time.h"
#include <cstdlib>
#include <iostream>
using namespace FastMath;
using namespace std;
void FMatrix::initMatrix(unsigned int r,unsigned int c, bool initValues)
{
rw=r;
cl=c;
val=new double[rw*cl];
#ifdef _DEBUG
cout <<"++ Matrix created." << endl;
#endif
if (initValues)
{
for (int i=0;i<rw;i++)
{
for (int j=0;j<cl;j++)
*(val+i*cl+j)=0;
}
}
}
FMatrix::FMatrix()
{
}
FMatrix::FMatrix(unsigned int dim,bool initValues)
{
initMatrix(dim,dim,initValues);
}
FMatrix::FMatrix(unsigned int rows,unsigned int columns,bool initValues)
{
initMatrix(rows,columns,initValues);
}
FMatrix::FMatrix(unsigned int dim)
{
initMatrix(dim,dim,true);
}
FMatrix::FMatrix(unsigned int rows, unsigned int columns)
{
initMatrix(rows,columns,true);
}
FMatrix::FMatrix(const FMatrix &m)
{
initMatrix(m.rw,m.cl,false);
for (int i=0;i<rw;i++)
{
for (int j=0;j<cl;j++)
*(val+i*cl+j)=*(m.val+i*cl+j);
}
}
FMatrix::~FMatrix()
{
destroy();
}
void FMatrix::destroy()
{
delete[] val;
#ifdef _DEBUG
cout << "-- Matrix destroyed." << endl;
#endif
}
FMatrix* FMatrix::CreateIdentity(unsigned int dim)
{
FMatrix *t=new FMatrix(dim,false);
double* pTval=t->val;
int c=t->cl;
for (register int i=0;i<t->rw;i++)
{
for (register int j=0;j<c;j++)
{
if (j==i)
*(pTval+i*c+j)=1;
else
*(pTval+i*c+j)=0;
}
}
pTval=NULL;
return t;
}
FMatrix* FMatrix::CreateFull(unsigned int rows, unsigned int columns, double value)
{
FMatrix *t=new FMatrix(rows,columns,false);
double* pTval=t->val;
int c=t->cl;
for (register int i=0;i<t->rw;i++)
{
for (register int j=0;j<c;j++)
{
*(pTval+i*c+j)=value;
}
}
pTval=NULL;
return t;
}
FMatrix* FMatrix::CreateRandomIntMatrix(unsigned int rows, unsigned int columns, int lowest, int highest)
{
FMatrix *t=new FMatrix(rows,columns,false);
double* pTval=t->val;
int c=t->cl;
SYSTEMTIME lp;
GetSystemTime(&lp);
srand(rand()*(unsigned int)lp.wMilliseconds);
for (register int i=0;i<t->rw;i++)
{
for (register int j=0;j<c;j++)
{
*(pTval+i*c+j)=int(lowest+double(rand())/RAND_MAX*(highest-lowest)+.5);
}
}
pTval=NULL;
return t;
}
FMatrix* FMatrix::CreateRandomDblMatrix(unsigned int rows, unsigned int columns, double lowest, double highest)
{
FMatrix *t=new FMatrix(rows,columns,false);
double* pTval=t->val;
int c=t->cl;
SYSTEMTIME lp;
GetSystemTime(&lp);
srand((unsigned int)lp.wMilliseconds);
for (register int i=0;i<t->rw;i++)
{
for (register int j=0;j<c;j++)
{
*(pTval+i*c+j)=lowest+double(rand())/RAND_MAX*(highest-lowest);
}
}
pTval=NULL;
return t;
}
FMatrix& FMatrix::operator =(const FMatrix &m)
{
if (this!=&m)
{
double* pMval=m.val;
rw=m.rw;
cl=m.cl;
destroy();
initMatrix(rw,cl,false);
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(val+i*cl+j)=*(pMval+i*cl+j);
}
}
pMval=NULL;
}
return *this;
}
FMatrix& FMatrix::operator -() const
{
FMatrix *t=new FMatrix(rw,cl,false);
double* pTval=t->val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(pTval+i*cl+j)=-*(val+i*cl+j);
}
}
pTval=NULL;
return *t;
}
FMatrix& FMatrix::operator +(const FMatrix &m) const
{
if (!AreSameSize(*this,m))
{
throw exception("Matrix can not be added. Dimensions do not match.");
}
FMatrix *t=new FMatrix(rw,cl,false);
double* pTval=t->val;
double* pMval=m.val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(pTval+i*cl+j)=*(val+i*cl+j)+*(pMval+i*cl+j);
}
}
pTval=NULL;
pMval=NULL;
return *t;
}
FMatrix& FMatrix::operator -(const FMatrix &m) const
{
if (!AreSameSize(*this,m))
throw invalid_argument("Matrix can not be added. Dimensions do not match.");
FMatrix *t=new FMatrix(rw,cl,false);
double* pTval=t->val;
double* pMval=m.val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(pTval+i*cl+j)=*(val+i*cl+j)-*(pMval+i*cl+j);
}
}
pTval=NULL;
pMval=NULL;
return *t;
}
FMatrix& FMatrix::operator *(double d) const
{
FMatrix *t=new FMatrix(rw,cl,false);
double* pTval=t->val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(pTval+i*cl+j)=*(val+i*cl+j)*d;
}
}
pTval=NULL;
return *t;
}
FMatrix& FMatrix::operator !() const
{
FMatrix *t=new FMatrix(cl,rw,false);
double* pTval=t->val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
*(pTval+j*rw+i)=*(val+i*cl+j);
}
}
pTval=NULL;
return *t;
}
bool FMatrix::operator ==(const FMatrix &m) const
{
if (!AreSameSize(*this,m))
return false;
double *pMval=m.val;
for (register int i=0;i<rw;i++)
{
for (register int j=0;j<cl;j++)
{
if (*(pMval+i*cl+j)!=*(val+i*cl+j))
return false;
}
}
pMval=NULL;
return true;
}
bool FMatrix::operator !=(const FMatrix &m) const
{
return !(*this==m);
}
double FMatrix::GetItem(unsigned int r, unsigned int c) const
{
return *(val+r*cl+c);
}
void FMatrix::SetItem(unsigned int r, unsigned int c, double value)
{
*(val+r*cl+c)=value;
}
int FMatrix::GetRowCount() const
{
return rw;
}
int FMatrix::GetColumnCount() const
{
return cl;
}
bool FMatrix::AreSameSize(const FMatrix &m1, const FMatrix &m2)
{
return (m1.rw==m2.rw)&&(m1.cl==m2.cl);
}
I'm really confused because I dont know what I'm doing wrong. The thing is if I use in the App test the static constructors (CreateRandomIntMatrix for example) and I dont have to manually delete them from the app test everything works greate and the destructor of my two matrixes is called all by itself. But when I explecitly instantiate with the new operator in my app test and thus have to delete them myself in that same app I get the errors described above.
Any help plz?
P.D. Sorry about the long post.
|
|
|
|
|
gumi_r@msn.com wrote: well allthough I'm new to C++ I've done my share of development in more user friendly environments, mainly C#.
This is the C++/CLI forum. IF you want to learn C++, you need the visual C++ forum. C++/CLI is .NET C++.
<br />
FMatrix *a=new FMatrix(5); <br />
cout << "A is a [" << a->GetRowCount() << "x" << a->GetColumnCount() << "] matrix." << endl; <br />
delete a;<br />
Why create it as a pointer at all ?
Your destructor is obviously causing the error. Set a breakpoint and step through to see what it is. I can't see the initMatrix method, but for a starter, any constructor should set all pointers to NULL. A pointer that was not set by initMatrix and was not set to NULL is a very likely cause of this error.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The only pointer in my class is double* val that is a double array that stores all my matrix items.
Destructor only executes delete [] val and sets the pointer to NULL on exit.
No other pointers are set during the constructor.
The thing is that I'm not getting an error anywhere that i can see when I step through with the debugger. Everything executes perfectly if I put a breakpoint on the exit bracket of my destroy() method (Destructor calls this method, I implemented this way so I can log every call to my destroy method even if called from inside the class like in the assign operator where I have to delete *val before reassigning.) Once I hit the breakpoint and I press continue and the only thing it should do is step out of the Destroy() method and return to the the Test app I get the error. I dont know what's going on at all.
1. Only pointer in my class is private member double *val;
2. Only pointer used in constructor is *val that is set with a new double[whatever];
3. Destructor calls private method destroy() where I delete [] val and log to the console that the destructor was called.
You can see the initMatrix method in my first post, but just for clarification, I'll show the involved methods here:
<rep>
<br />
void FMatrix::initMatrix(unsigned int r,unsigned int c, bool initValues)<br />
{<br />
rw=r;<br />
cl=c;<br />
val=new double[rw*cl];<br />
<br />
#ifdef _DEBUG<br />
cout <<"++ Matrix created." << endl;<br />
#endif<br />
<br />
if (initValues)<br />
{<br />
for (int i=0;i<rw;i++)<br />
{<br />
for (int j=0;j<cl;j++)<br />
*(val+i*cl+j)=0;<br />
}<br />
}<br />
}<br />
<br />
FMatrix::FMatrix(unsigned int dim)<br />
{<br />
initMatrix(dim,dim,true);<br />
}<br />
<br />
FMatrix::~FMatrix()<br />
{<br />
destroy();<br />
}<br />
<br />
void FMatrix::destroy()<br />
{<br />
delete[] val;<br />
val=NULL;<br />
#ifdef _DEBUG<br />
cout << "-- Matrix destroyed." << endl;<br />
#endif<br />
}<br />
|
|
|
|
|
Are r and c both > 0 when this is called ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Yes, I'm calling
FMatrix::FMatrix(5);
I should add that every once in while when I build for debugging, I get a message warning me that: "The project is out of date. FastMath - Debug Win 32". Could the problems I'm having be something other that a coding problem? Something that goes wrong when building or something?
|
|
|
|
|
OK, yeah, if this is in a dll, it's possible you're not building the dll, or the one that your main program is seeing, is out of date.
Step into the code. Watch what the constructor and destructor do, assuming hte other methdos called are not changing state.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
No I suspected it could have something to do with me not linking well the two projects so I even built it all in one same project...included header and source files of my FMatrix class in the Test app and removed any linking to the dlls...just compiled it as one console app. I still got the same error and I still couldn't catch it with the debugger step by step.
I'm giving up, at least today. Thanks for all the help.
|
|
|
|
|