|
I'm using Visual Studio 2008.
I had been careful to paste the DLL in the folder with the .exe file... But it still doesn't work...
It is the first time I tried to do a DLL, it is possible I forgot something, or maybe I'm doing something wrong...
|
|
|
|
|
Does your DllMain() function return TRUE?
A Dll will only load if its DllMain() function returns TRUE.
|
|
|
|
|
I think my DLL code is correct, because I used the DLL in a c# project and it loaded and worked just fine.
My problem is to load in a c++ project.
I read that if we want to use a DLL without de lib file, we must paste de DLL file in the debug project folder (and I did it, because I want it to work without the code files).
Then I used
HINSTANCE myDll = LoadLibrary((LPCWSTR)"Testing.dll");
if(myDll)
Console::WriteLine("DLL loaded \n");
else
Console::WriteLine("DLL failed to load \n");
it always "DLL failed to load ", it doesn't return any error.
Did I forgot something, or am I doing something wrong? (I'm starting with c++, so possible I'm making some mistake).
Thanks.
|
|
|
|
|
Change your code so that it reads as follows:
HINSTANCE myDll = LoadLibrary((LPCWSTR)"Testing.dll");
DWORD Error = GetLastError();
if (myDll)
Console::Writeline("Dll Loaded");
else
Console::Writeline("Dll Not Loaded");
Put a breakpoint at the line that says "Not Loaded."
When the program breaks, inspect the value of the variable Error.
That will be the Windows error code for what went wrong. Post the Error code here, and maybe we can help you figure it out.
|
|
|
|
|
Hi.
Thanks a lot for your help.
I did what you suggested and I got error 126 (unsigned int).
I made a litle search to understand error 126 and its causes...and I found out that I can't cast char* to LPCWSTR, and the solution is just "Use Multi-Byte Character Set" within the projects properties. And it works just fine.
Best regards,
Carla
|
|
|
|
|
Hi,
How do i convert a const string& to CByteArray ?
I have to convert the string to CByteArray and pass the member functions GetData() and GetSize() to a method as parameters
Is it possible or is there an alternative way of converting string to CByteArray.
An example would be appreciated.
Thanks in advance,
Regards,
Mayur M
|
|
|
|
|
Try (I didn't test it...)
CString str = _T("Hi");
CByteArray arr;
int iSize = (str.GetLength()+1) * sizeof(TCHAR)
const BYTE * pByte = (const BYTE *) (LPCTSTR) str;
for (i = 0; i < iSize; i++)
{
arr.Add(pByte[i]);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your reply.
The code snippet works fine. But the snippet is for convertion of CString to CByteArray. But i'm looking for a const string conversion to CByteArray.
Even if i use the CString conversion to CByteArray, is there any inbuilt methods rather than using the for loop.
Regards,
Mayur M
|
|
|
|
|
mayur8u wrote: But i'm looking for a const string conversion to CByteArray.
Are you talking about std::string?
mayur8u wrote: Even if i use the CString conversion to CByteArray, is there any inbuilt methods rather than using the for loop.
Yes, you may use CByteArray methods SetSize and Getdata to copy the string content into the array buffer.
CString str = _T("Hi");
CByteArray arr;
int iSize = (str.GetLength()+1) * sizeof(TCHAR)
arr.SetSize(iSize);
const BYTE * pByte = (const BYTE *) (LPCTSTR) str;
CopyMemory( arr.GetData(), pByte, iSize);
As usual, the test is up to you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ya! i'm talking about converting from std::string to CByteArray.
If there is no solution then i might have to go to CString. (Last option)
|
|
|
|
|
std::string str("Hi");
int iLen = str.length();
CByteArray arr;
arr.SetSize(iLen);
CopyMemory( arr.GetData(), str.c_str(), iLen);
Please note, the above code is not adding the null terminator at the tail of the array.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How about the CByteArray to std:string?
|
|
|
|
|
Hi,
I'm able to convert const string& to CByteArray using the
memcpy(byteArr.GetData(), source.c_str(), source.length());
Does converting back the CByteArray to const string& work the same way using memcpy?
Regards,
Mayur M
|
|
|
|
|
char str[] = "abcdef";
int iSize = strlen(str);
BYTE * pByte = (BYTE *) str;
CByteArray arr;
for (int i = 0; i < iSize; i++)
{
arr.Add(pByte[i]);
}
the loop is must use.
|
|
|
|
|
I have a code written as:-
#include<string>
#include <iostream>
#include <iomanip>
using namespace std;
// This class Package is the base class for two other classes, TwoDayPackage and OverNightPackage.//
class Package // begins class Package
{
public:
Package(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double = 0.0, double = 0.0); // constructor
// set and get functions for sender
void setSendName(const string &);
string getSendName() const;
void setSendAdd(const string &);
string getSendAdd() const;
void setSendCity(const string &);
string getSendCity() const;
void setSendSt(const string &);
string getSendSt() const;
void setSendZip(const string &);
string getSendZip() const;
// set and get functions for recipient
void setRecName(const string &);
string getRecName() const;
void setRecAdd(const string &);
string getRecAdd() const;
void setRecipientCity(const string &);
string getRecipientCity() const;
void setRecSt(const string &);
string getRecSt() const;
void setRecZip(const string &);
string getRecZip() const;
void setWt(double);
double getWt() const;
void setShip(double);
double Package::getShip() const
{
return shipCost;
}
double Package::CalCost() const
{
return (wt*shipCost);
}
private:
string sendName;
string sendAdd;
string sendCity;
string sendState;
string sendZip;
string recName;
string recAdd;
string recCity;
string recState;
string recZip;
double wt;
double shipCost;
};
Package::Package(const string &sname, const string &saddress, const string &scity, const string &sstate, const string &szipcode, const string &rname, const string &raddress, const string &rcity, const string &rstate, const string &rzipcode, double wt, double shipCost)
{
sendName = sname;
sendAdd = saddress;
sendCity = scity;
sendState = sstate;
sendZip = szipcode;
recName = rname;
recAdd = raddress;
recCity = rcity;
recState = rstate;
recZip = rzipcode;
setWt(wt);
setShip(shipCost);
}
void Package::setSendName(const string &sname)
{
sendName = sname;
}
string Package::getSendName() const
{
return sendName;
}
void Package::setSendAdd(const string &saddress)
{
sendAdd = saddress;
}
string Package::getSendAdd() const
{
return sendAdd;
}
void Package::setSendCity(const string &scity)
{
sendCity = scity;
}
string Package::getSendCity() const
{
return sendCity;
}
void Package::setSendSt(const string &sstate)
{
sendState = sstate;
}
string Package::getSendSt() const
{
return sendState;
}
void Package::setSendZip(const string &szipcode)
{
sendZip = szipcode;
}
string Package::getSendZip() const
{
return sendZip;
}
void Package::setRecName(const string &rname)
{
recName = rname;
}
string Package::getRecName() const
{
return recName;
}
void Package::setRecAdd(const string &raddress)
{
recAdd = raddress;
}
string Package::getRecAdd() const
{
return recAdd;
}
void Package::setRecipientCity(const string &rcity)
{
recCity = rcity;
}
string Package::getRecipientCity() const
{
return recCity;
}
void Package::setRecSt(const string &rstate)
{
recState = rstate;
}
string Package::getRecSt() const
{
return recState;
}
void Package::setRecZip(const string &rzipcode)
{
recZip = rzipcode;
}
string Package::getRecZip() const
{
return recZip;
}
void Package::setWt(double wt)
{
wt = (wt < 0.0 ) ? 0.0 : wt;
}
double Package::getWt() const
{
return wt;
}
void Package::setShip(double shipCost)
{
shipCost = ( shipCost < 0.0) ? 0.0 : shipCost;
}
// This class TwoDayPackage is the first derived class from class Package.//
class TDP : public Package
{
public:
TDP(const string &, const string &, const string &, const string &, const string &, const string &,
const string &, const string &, const string &, const string &, double = 0.0, double = 0.0, double = 0.0); // constructor
void setFlatFee(double);
double getFlatFee() const;
double CalCost() const;
private:
double flatFee;
};
// This class OverNightPackage is the second derived class from class Package.//
class ONP : public Package
{
public:
ONP(const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, const string &, double=0.0, double=0.0, double=0.0); // constructor
void setFee(double);
double getFee() const;
double CalCost() const;
private:
double fee;
};
// This is the test program.//
int main()
{
ONP box("name", "123 this Street", "boston", "ma", "12345", "receiver", "123 that street", "medford", "ma", "25341", 10.00, 1.50, .85);
TDP parcel("name2", "123 1st Street", "orlando", "fl", "56474", "receiver2", "833 2nd Street", "miami", "fl", "88472", 15.00, 1.05, 5.00);
cout << fixed << setprecision(2);
cout << "To ship a box with overnight delivery\n";
cout << "The sender " << box.getSendName()<< "\n";
cout << " " << box.getSendAdd() << "\n";
cout << " " << box.getSendCity() << " " << box.getSendSt() << " " << box.getSendZip() << "\n";
cout << "The recipient " << box.getRecName()<< "\n";
cout << " " << box.getRecAdd() << "\n";
cout << " " << box.getRecipientCity() << " " << box.getRecSt() << " " << box.getRecZip() << "\n";
cout << "The cost is $ " <<box.CalCost() << "\n";
cout << "\n\n";
cout << "To ship a parcel with 2 day delivery\n";
cout << "The sender " << parcel.getSendName()<< "\n";
cout << " " << parcel.getSendAdd() << "\n";
cout << " " << parcel.getSendCity() << " " << parcel.getSendSt() << " " << parcel.getSendZip() << "\n";
cout << "The recipient " << parcel.getRecName()<< "\n";
cout << " " << parcel.getRecAdd() << "\n";
cout << " " << parcel.getRecipientCity() << " " << parcel.getRecSt() << " " << parcel.getRecZip() << "\n";
cout << "The cost is $ "<<parcel.CalCost() << "\n";
system("pause");
return 0;
}
The calcost function needs some change as it is the source of error.Somebody help.
modified on Monday, February 16, 2009 12:15 PM
|
|
|
|
|
Keep your question concise! No-one will want to read all of that to answer your question!
Regards,
--Perspx
"A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year." -Andrew Tanenbaum
"Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer." -Fred Brooks
|
|
|
|
|
Didn't this come out of Deitel's "C++: How to Program" book? Is this your assignment?
"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
|
|
|
|
|
yes but it is from exercise.Can you tell me where solutions are available.it would help me a lot
|
|
|
|
|
tksrules wrote: Can you tell me where solutions are available.
In the classroom/lab. Does the instructor offer a Q&A session either at the start or near the end of class?
tksrules wrote: it would help me a lot
Quite the opposite, actually. You can't post a big wad of code on some Internet forum and ask someone to help you figure it out. I guess you can, but then you haven't been helped. At a minimum, you need to isolate the problem down to a small handful of statements (the actual number varies, but if it's more than a dozen, that's likely too many). Everything else is irrelevant and only acts as a hinderance.
Instead of trying to work through 200 lines of code, why not start with a smaller project, get it working, and then add to it until the problem shows itself?
This forum is frequented by a lot of sharp people that will gladly help you, but they aren't going to do it for you. You might look real closely at Package::setWt() and Package::setShip() .
"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 solving assignment myself...i will take ur advice.
|
|
|
|
|
We (Italians) say 'tana!' in such circumstances...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Which translates to what in English?
"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
|
|
|
|
|
Well, I'll try...
When playing hide-and-seek, if you eventually discover your opponent hiding place then say 'tana!' and win the game.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
So, that translates to "gotcha" in English. Hand in the cookie jar?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Yes, 'hand in the cookie jar' looks appropriate.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|