|
I wrote a DLL in C++ that I am testing by calling it from VB. the dll works and does what it's supposed to do, but when I end the running vb demo, I get a heap memory error. any idea what's up?
thank you.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
The DLL is not cleaning up after its' self. Or the demo program is not calling the functions in the DLL that are reasponsible for cleaning up.
INTP
|
|
|
|
|
there is only one function in the dll, so it must be me not cleaning up after myself. Can you give me any hints on how to go about doing this?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Since you wrote the DLL your self then you need to see where you are allocating memory and make sure it is released either when the DLL is unloaded or before the function call returns.
If the allocated memory block is what is being returned then you should probably provide a second function in your DLL used to release it after you are finished using it.
In C/C++ the calls may look something like this:
BYTE* pData = GetData(arguments);
ReleaseData(pData);
In VB it may look like this:
VARIANT data
data = GetData arguments
ReleaseData data
Using Get and Release functions is a versatile pattern, as it may allow for data hiding. An example of the is GetDC and ReleaseDC, where a handle is retreived and then released after you are finish using it. You do not need to know if the handle is a simple index value or a memory pointer, all you need to know is what functions to call in order to use it.
INTP
|
|
|
|
|
I made sure that I released all variables that were allocated on the heap. But just to see how far I get, I put a frivolous return in the dll in a certain space, and now it works fine. But if I move it down a few lines, I get that error again. Here's an example:
sColumns = sColumns.Left(sColumns.GetLength() - 1);
sColumns = "CREATE TABLE " + strTblName + " (" + sColumns + ")";
pDB.ExecuteSQL(sColumns);
<-- Works fine if I put it on this line
CDBFRecordset m_Set;
return 1;
I'm guessing it has something to do with this class (CDBFRecordset) because even if I put the return before this object variable it compiles without warnings. If I put it in the bottom position I get warnings like this:
warning LNK4098: defaultlib "mfcs42d.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
do you have any idea what's wrong?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
The error message means exactly what is says, type LNK4098 as the index in MSDN library for an expanation. The only reason I can think of why moving the return statment stoped the warning message, is that the complier upon seeing an early return statement probably proceded to ignore (not compile) the code following (with in the function) that statement and therefore did not find the problem. When you compile you code set the warning level to 4, that may cause it to generate an unreachable code warning, which suggest that it may not bother looking at that part of the code for errors.
There is also the possibility that the debug version of the library is conflicting with the non-debug version of the libaray. I may be mistaken but the 'd' at the end of the library name indicates that it is the debug version, if that is the case it may conflicking with the non-debug version (probably mfcs42.lib). You might want to check your project settings to see if you are linking to the correct libraries.
The article LNK4098 will tell you how to determine which libraries you are linking to.
INTP
|
|
|
|
|
Hi
In windows 2000 or any other operating system when we right click on MYComputer on desktop and see the general properties we see one OEM number. Like "Registered to some company name ansd a number like 56789-OEM-99456-5355
Can any body suggest me how to get this number through Programming in VC++ 6.0. I tried GetsystemInfo with dwOemID but it is giving me 0.
Thanks
Shailesh
|
|
|
|
|
Try the following registry value:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I got this odd problem today (well, one of my testers got it):
I got a function that returns a pointer to my main window, casted to the correct type. It looks something like this:
CMyMainWnd* _GetMainWnd()
{
return dynamic_cast<cmymainwnd*>(AfxGetMainWnd());
}
The strange thing is that this fails at one point. I first thought that it was due to the function being called from the wrong thread, but that wasn't the case. I took a look at what AfxGetMainWnd() returned, and it was the correct window (at least the title was correct; I never had this problem, so I can't debug it). The window title clearly states that this is "CMyMainWnd", but the dynamic cast still fails and returns 0.
What could cause this problem?
Maybe I should just use a stupid cast and cross my fingers
|
|
|
|
|
It looks like AfxGetMainWnd() will return NULL if it is called from a non-GUI thread. ie. A Worker thread. Or of course if the main window in a GUI thread is not of type CMyMainWnd or derived from it.
Simple enough to test what AfxGetMainWnd() returns and ASSERT or log errors.
BTW. We can't see you <cast_type> You need to use the < and > and pre and code Formatting Toolbar options when embedding code in posts.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
No, AfxGetMainWnd() does not return NULL. How else could I get the Window caption?
The thing is that the caption is correct, just the caption of the main window as it should be. So, I assume that AfxGetMainWnd() returns the correct window pointer, but the cast just fails.
And thanks for the hint on the < and >... I will keep that in mind next time.
|
|
|
|
|
Neville Franks wrote:
BTW. We can't see you <cast_type> You need to use the < and > and pre and code Formatting Toolbar options when embedding code in posts.
It looks like it is:
return dynamic_cast<CMyMainWnd*>(AfxGetMainWnd());
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
why dynamic_cast and not static_cast?
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
You'd have to ask Tak that one. I was simply helping Neville see potentially hidden text.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I have an ATL com dll and i want to get a function from it. The question is what is the syntax.
Lets say the name of my dll is: Test and the name of my function is getName ?.
|
|
|
|
|
The syntax... the syntax of what?
The syntax of the function? Do you mean the function prototype, do you need to know the function's prototype?
Or perhaps you want to know how to go about calling that function.
Please clarify.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
I want to know how to call the function.
|
|
|
|
|
You'd do it the same way you call any COM method. First you need to get a hold of the COM object, and then you can call its method. There are several alternatives:
- Import the DLL's type library into your project. Look at the #import directive.
- Use the Class Wizard to add a class wrapper for the COM object. Open Class Wizard/Add Class/From a type library.
- Use one of the template classes like CComQIPtr (ATL), or com_ptr_t .
- Use the CoCreateInstance API.
If my memory serves me right the first option is the easiest -- look into it. Good luck!
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
|
I use the fetch_row method for mysql and then retrieve the info from that field with a simple
value = row[i];
this works well with all other fields, but for some reason date fields only return me a 0000-00-00
does anyone know what's going on?
thanks in advance
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hello,
I want to have a function that returns a vector.. I'm unsure on how to define this function.
here's how i define the vector..
class CXMLParser
{
public:
CXMLParser(CString strUrl);
virtual ~CXMLParser();
.... code snipped ......
public:
struct RSS_struct {
// Channel info.
CString strChannelTitle,
strChannelLink,
strChannelDescription,
strChannelDate;
// Item info.
CString strTitle,
strLink,
strDescription,
strDate;
};
std::vector<RSS_struct> v_RSS;
};
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Include a method signature in your header file for the class, something like the following:
std::vector<RSS_struct> GetData();
Write your function in the .cpp file:
std::vector<RSS_struct> GetData()
{
std::vector<RSS_struct> vect;
RSS_struct data;
vect.push_back(data);
return vect;
}
Don't forget to #include <vector> and using namespace std; .
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thank you!
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
First I recommend you typedef your vector type:
typedef std::vector<RSS_struct> RSSVector;
Then you can define your v_RSS like this:
RSSVector v_RSS;
This makes adding your member function easy:
RSSVector& GetRSSVector() { return v_RSS; }
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
I would advise against this, it makes your code unreadable. At least, it's made code I've had to maintain unreadable.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|