|
It would be of help to know the difference between Excel and your program: Excel doesn't throw a bad_alloc exception and crash to death. Your application does.
Which means that there's something wrong (you don't know if it's at the library side or at the consumer side), so I asked you to debug them together. You may drop my idea of using debugging symbols if you didn't like it.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Yes, acctually that's my problem.
I have done a simple test:
Create a dll with a function. (for example:
__declspec(dllexport) int test1(const std::string& chain)<br />
{<br />
std::string test;<br />
<br />
test = "testing: ";<br />
test += chain;<br />
return 13;<br />
} )
Create a exe that import the funtion. (for example:
#pragma comment(lib, "DllTest.lib")<br />
__declspec(dllimport) int test1(const std::string& cadena); )
Call to the function of the dll form the exe. (for example:
int io;<br />
std::string stTest;<br />
<br />
io = test1("testing testing"); )
And the results are:
Both in debug -> works (so I cannot find information about the crash)
Both in release -> works
One in debug and one in release -> Crash to death
I think that the problem is in the project options, because there is nothing strange in the code.
|
|
|
|
|
Yes he can.
Be careful: don't challenge Rajesh...
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]
|
|
|
|
|
Ok Ok..... 
|
|
|
|
|
Epi wrote: "Unhandled exception at 0x77d4dd50 in PruebaLinkado.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012c160.."
Every time a question with an error description like this it will be followed by another question: have you actually used your debugger?
On the other hand, mixing debug and release built EXE and DLLs will in many cases lead to exceptions that complain about dynamic memory allocations. This is due to that new is redefined in the debug version and adds some book keeping features in order to detect buffer overruns and such. It seems like this is your current problem.
Epi wrote: The dll has "Multi-threaded DLL (/MD)" option
And the exe file has "Multi-threaded (/MT)" option.
Shouldn't one of them be a debug version?
You may also benefit from reading this excellent article[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I am using the debugger, and now I change the options of the executable to Multi-threaded Debug (/MTd) and I get the same.
For instance I am working with a little example.
In this example in the dll I have this funtion:
__declspec(dllexport) int test1(const std::string& chain)<br />
{<br />
std::string test;<br />
<br />
test = "testing: ";<br />
test += chain;<br />
return 13;<br />
}
and I am calling it from the exe.
I import it:
<br />
#pragma comment(lib, "DllTest.lib")<br />
__declspec(dllimport) int test1(const std::string& cadena);
and after I call it
int io;<br />
std::string stTest;<br />
io = test1("testing testing");
When I call the function test1, as you predict I get a bad ptr 0xcccccccc.... So should be in the size...
|
|
|
|
|
Epi wrote: I change the options of the executable to Multi-threaded Debug (/MTd) and I get the same.
Linking with the debug built version of a library you're using when you're building the debug version of your own binary seems like a Good Idea.
Yes, you will get the same result, but now you're using the correct version of the runtime libraries if you happen to run into other problems.
Epi wrote: When I call the function test1, as you predict I get a bad ptr 0xcccccccc....
This suggests an uninitialized stack value.
Read more here[^].
I suspect this to origin from the mix up between debug and release versions and the fact the a debug built binary will add book keeping for both the stack and heap.
Stop mixing them and you'll probably get the result you want.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I am about to fininsh the article Debug vs Release it is really interenting.
But I think it is not a code problem, because in the test that I have done just now, I haven't anything else except an executable that call a function in a dll passing it a string. No pointers, no arrays...
|
|
|
|
|
I guess it is due to a mismatch between the runtime library which is used for your exe and for your dll.
Epi wrote: I haven't anything else except an executable that call a function in a dll passing it a string. No pointers, no arrays...
No really correct: a std string allocates an array internally, and that's what causing the troubles. You are allocating it in your executable and trying to release it in your dll (or the other way around). As you are using two different runtime libraries, there's a crash when the destructor of the string is called because the dll and the exe do not use the same heap.
I'm not really an expert there but I encountered that problem before, I think you are facing the same problem.
|
|
|
|
|
Ok. Thank you,
Also is related the project option
Basic RunTime Check,
"Default" in all the configurations
Now it works,
Thank you very much to all of you
|
|
|
|
|
Hi, I am creating one sample application that uses SQL Server and create one table having ID and Title (Unicode data).My problem is that i am using unicode data and when i open the table, "Question mark " is displayed in Title instead of unicode data. My workspace is unicode compiled and i am using nvarchar for lingual data as a variable. Here is my code
CDatabase db;
CString strLingual = L"";
m_edt_lingual.GetWindowTextW(strLingual);
CString strQuery;
try
{
if (db.Open(NULL, FALSE, FALSE, _T("Driver={SQL Native Client};Server=SHILPI_PHADNIS\\SQLEXPRESS;Database=TransTool;Uid=sp;Pwd=np;")))
{
db.ExecuteSQL(_T("CREATE TABLE WDCheckLingual (ID INT, Title NVARCHAR(50))"));
for (int i = 0; i < 10; i++)
{
strQuery.Format(_T("INSERT INTO WDCheckLingual (ID, Title) VALUES (%d, '%s')"),
i + 1, strLingual);
db.ExecuteSQL(strQuery);
}
}
}
catch (CException *e)
{
e->ReportError();
e->Delete();
}
Thanks in advance....
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Hello,
This is with regards to the query you asked me here[^]. Somehow, I am unable to add a reply there. So, I sent you an email. If you have not received, feel free to reply here and I shall assist you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi all,
i have created a modeless dialog box,but this Modeless dialog box not display in center of parent dialog box.
i want to show it in center of parent dialog box.
please tell me what can i do for this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
toggle the item "Center" in the property window to "true".
|
|
|
|
|
i also try this, after using this modeless dialog box display in center of monitor.
if i move the parent dialog box in any side ,here the modeless diaolg box display in center of monitor not in center of parent dialog box.
here one mor problem,if i run two instance of my application than the modelss of both exe overlapped.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
There is trick for to put the chld window at the center of parent. You have to disable the parent windows before creating the child and after creating the child, enable the parent window back.
EnableWindow( FALSE );
ChildWndobj.Create( ChildWnd::IDD, this );
EnableWindow( TRUE );
|
|
|
|
|
Thanks its works.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
New to me too!
Thanks,
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Iain Clarke wrote: New to me too!
Ya for me also. I just tried it when I saw the post.
|
|
|
|
|
Hi,
I have an application which uses ShellExecuteEx function to launch Outlook and attaching file.
************************************************************
shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = "open";
shExecInfo.lpFile = "outlook";
shExecInfo.lpParameters = "C:\Test.doc";
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_MAXIMIZE;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
************************************************************
I am using this functionality in my app ins such a way that once file attached i am proceeding with other functionality. But my problem is before file get attached my next step of application get executed.I want to get event or information that outlook is launched and file is get attached so that i can synchronize the functionality.
Please let me know how we can get the file attached event in outlook. Is it possible by using other API's like CreateProcess...etc....
Pls suggest.
THanks
SNI
|
|
|
|
|
To do this, I suspect you need to interface to Outlook using it's COM object model. I don't think ShellExecuteEx will cut it.
This article[^] shows how to talk to Outlook using Javascript. C++ is more involved - to get anywhere, you probably want to be using #import with Outlook's type library - use #import "progid:Outlook.Application" auto_search to get VC++ to generate classes for the Outlook object model.
Alternatively, this article[^] tells you how to do Office Automation with COM without using #import .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thanks for your reply. But I want to know the event by which I come to know whether file gets attached or not so i can move further for processing.
Any kind of idea will be helpful.
SNI
|
|
|
|
|
Yeah, it's a bit different than just launching outlook with a parameter when you use COM.
Here's some VBA that will start Outlook, create and send an e-mail.
Dim o As Object 'will be an Outlook.Application
Dim msg As Object 'will be a MailItem
Set o = CreateObject("Outlook.Application")
Set msg = o.CreateItem(0)
msg.Subject = "this is my subject"
msg.attachments.Add "path to the attachment"
msg.body = "my message"
msg.Recipients.Add "an e-mail address"
msg.send
You can replicate that relatively easily using the #import approach to interfacing with Outlook.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
C++ code for the VBA I posted - note that it's pretty much a direct translation...
#import "progid:Outlook.Application" auto_search
int main(int, char**)
{
try
{
CoInitializeEx(0, COINIT_APARTMENTTHREADED);
Outlook::_ApplicationPtr ol(__uuidof(Outlook::Application));
Outlook::_MailItemPtr msg(ol->CreateItem(Outlook::olMailItem));
msg->Subject = "this is my subject";
msg->Attachments->Add("path to the attachment");
msg->Body = "my message";
msg->Recipients->Add("an e-mail address");
msg->Send();
}
catch (_com_error& e)
{
std::cerr << (char*)e.Description() << std::endl;
}
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Here is the code snippet.
class Super
{
public:
Super(){}
virtual void someMethod() {cout<<"in Super class"<<endl;}
};
class Sub : public Super
{
public:
Sub();
virtual void someMethod(){cout<<"in Sub class"<<endl;}
};
Sub mySub;
Super& ref =mySub;
ref.someMethod();
I don't really understand how the compiler works when it comes to the statement ref.someMethod(); . I guess the compiler first find someMethod() method in the Sub class. If doesn't find, then enter base class---Super class to find it.
above explanation is correct?
------------
If altering someMethod() in Sub class like this:
virtual void someMethod(int i){cout<<"in Sub class"<<endl;}<br />
what happens when the compiler runs ref.someMethod(); statement?
Obviously the output is "in Super class".
------------
If the someMethod() in Sub class is
virtual void someMethod(int i = 1){cout<<"in Sub class"<<endl} <br />
when the compiler runs ref.someMethod(); statement,what is the output?
In VS 2005,the output is "in Super class". I feel it is hard to understand,I believe the right result is "in Sub class".
Anyone could give me some idea,thanks in advance.
sharion
|
|
|
|