|
spot on Matthew!
I did a disassembly and ds:dword_4110E8 is indeed in .rdata and hence the error.
the first issue, I am still getting it even with optimization off.
<br />
_main proc near ; CODE XREF: start+AFp<br />
.text:00401080 push 14h<br />
.text:00401082 push offset unk_4140B0<br />
.text:00401087 push 0Ch<br />
.text:00401089 mov ecx, offset unk_417EE0<br />
.text:0040108E mov ds:dword_4110E8, 14h<br />
.text:00401098 call sub_4010B0<br />
.text:0040109D push eax<br />
.text:0040109E call sub_4014E0<br />
.text:004010A3 add esp, 8<br />
.text:004010A6 mov ecx, eax<br />
.text:004010A8 call sub_4010B0<br />
.text:004010AD retn<br />
.text:004010AD _main endp<br />
<br />
.rdata:004110E8 dword_4110E8 dd 0Ch <br />
modified on Friday, April 18, 2008 4:38 PM
|
|
|
|
|
<br />
void main()<br />
{ <br />
int *px;<br />
const int p = 99;<br />
px = (int *)&p;<br />
*px = 77;<br />
int y = p;<br />
}<br />
I did a disassembly of the above (VS 6 debug disassembly window) and this is what I found.
bit strange, I didnt expect the compiler to replace every instance of 'p' with its value like a #define.
I mean, I expected
<br />
0040127E mov dword ptr [ebp-0Ch],dword ptr [ebp-8] <br />
instead of
<br />
0040127E mov dword ptr [ebp-0Ch],63h<br />
complete disassembly
<br />
00401268 mov dword ptr [ebp-8],63h<br />
16: px = (int *)&p;<br />
0040126F lea eax,[ebp-8]<br />
00401272 mov dword ptr [ebp-4],eax<br />
17: *px = 77;<br />
00401275 mov ecx,dword ptr [ebp-4]<br />
00401278 mov dword ptr [ecx],4Dh<br />
18: int y = p;<br />
0040127E mov dword ptr [ebp-0Ch],63h<br />
|
|
|
|
|
error LNK2001: unresolved external symbol _pay
fatal error LNK1120: 1 unresolved externals
I am trying out a simple code and getting the above two errors. Kindly please help me out to get rid of them.
My code is below
Source..
#include "cdll.h"
#include <iostream.h>
__declspec(dllexport) int pay(int days,int salary)
{
int total;
total=days*salary;
return total;
}
Header...
#ifndef CDLL_H
#define CDLL_H
__declspec(dllexport)int pay(int days,int salary);
#endif
main..
#include <stdio.h>
#include "cdll.h"
#include <conio.h>
void main()
{
int days;
long salary;
char name[30];
printf("Enter name of employee:");
scanf("%s",name);
printf("\n Enter days worked:");
scanf("%d",&days);
printf("\n Enter wages per day:");
scanf("%d",&salary);
printf("\n NAME:%s",name);
printf("\n MONTHLY INCOME:%d",pay(days,salary));
getch();
}
Please help me out.
Thanks
modified on Friday, April 18, 2008 9:31 AM
|
|
|
|
|
pl_kode wrote: error LNK2001: unresolved external symbol _pay
See here.
pl_kode wrote: fatal error LNK1120: 1 unresolved externals
See here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Did you add cdll.lib to your project?
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
|
|
|
|
|
yes, after add cdll.lib in the project>settings...
I am getting an error saying that cannot open cdll.lib
|
|
|
|
|
pl_kode wrote: I am getting an error saying that cannot open cdll.lib
Is this a linker error?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
So does cdll.lib exist, and have you specified the correct path to it? When the linker says it cannot find a file, that's the place to start looking.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Please read the posting guidelines at the top of the forum, especially the bit about including code in pre tags, so we can see what files you are including.
But as was said, pay appears to be in a DLL, so you'll need to add (eg) CDLL.lib into your file (look at linker options).
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Hi to all,
I have some questions regarding DirectShow programming in VC++,
1. How to do MultiGraph Programming ?
I got a "GMFBridge" source code, but its gives compiling error. And I didn't understand the code.
2. Is there any alternative for "MPEG-2 Multicast Receiver" filter ?
Thanks in Advance.
Regards,
Aniket A. Salunkhe
|
|
|
|
|
Hello guys,
I've one problem.
Suppose user opens any .txt,.doc,.pdf file in local PC.
I want to read the attributes of the files like moddified,created,close.
How is this can be done with VC.
Thanks to all of you in Advance.
ritz1234
|
|
|
|
|
You can use CFile::GetStatus(), if you're using MFC.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Have you tried GetFileAttributes() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the co-operation friends,
But I want to find out if the file is
closed or not without opening the file.
Because in my application after user downloads the file I am going to
open that file using ShellExecute.I'll upload this file on the server
when the file is closed by the user.
How can I do this?
Once again thanks for the reply.
ritz1234
|
|
|
|
|
ritz1234 wrote: But I want to find out if the file is
closed or not without opening the file.
And what exactly does that have to do with reading the attributes of files?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Extremely Sorry,
I was my mistake.
I was thinking that it might give me that whether the file is opened or not.
Thanks for the reply.
But what about the solution?
ritz1234
|
|
|
|
|
Try opening the file in exclusive mode. If it fails, you'll know that it is open elsewhere.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
For testing pupose,
I've set the Timer and in the event of the timer I am trying to open the file.
I've run the application after manually openning the file.
After opening the file when I run the application it give me the message
of the file is opened.But when I close the file manually it doesn't give
the message of file is closed and I am getting the same message every
timer irrespective of the file is opened or not.Following is the code.
<br />
void CFilesDlg::OnTimer(UINT nIDEvent) <br />
{<br />
<br />
CDialog::OnTimer(nIDEvent);<br />
<br />
CFile ob;<br />
BOOL res;<br />
CFileException ex;<br />
res=ob.Open("C:\\Documents and Settings\\Rigel\\Desktop\\SerialNumbers.txt",CFile::modeRead | CFile::shareExclusive, &ex);<br />
if (!res)<br />
{<br />
<br />
TCHAR szError[1024];<br />
ex.GetErrorMessage(szError, 1024);<br />
MessageBox("The File is Closed");<br />
KillTimer(ID_TIMER1);<br />
}<br />
else<br />
{<br />
MessageBox("The File is opened");<br />
}<br />
}<br />
ritz1234
|
|
|
|
|
ritz1234 wrote: ...I am getting the same message every timer irrespective of the file is opened or not.
How are you "manually" opening the file? Notepad, for example, does not leave file handles open after it reads the contents.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I can't understand what you have said.
Please explain in brief.
ritz1234
|
|
|
|
|
You previously indicated that you were "manually" opening the file. I simply asked how.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
manually = double clicking the file with the mouse.
ritz1234
|
|
|
|
|
Whether you used the mouse or keyboard is irrelevant. What program are you using to open the file?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The program to open the file depends on its extension that is registered
with OS.
OS uses that extension to open an application for that file.
One more thing I want to know If I want to continue with this question
without posting new question for the issue
tommorow what should I do?
Right now I am not going anywhere, and waiting for your reply.
ritz1234
|
|
|
|