Sign in to follow this  
AWilson

help me solve lnk error

Recommended Posts

I'm using directx9 and VC++. I keep getting link 2019 errors from the structs in my headers when trying to build my program. Below is my error and the source that uses those structs. //error//////////////////////////////////// error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: struct MENUITEM_INT & __thiscall std::vector<struct MENUITEM_INT,class std::allocator<struct MENUITEM_INT> >::operator[](unsigned int)" (??A?$vector@UMENUITEM_INT@@V?$allocator@UMENUITEM_INT@@@std@@@std@@QAEAAUMENUITEM_INT@@I@Z) /////////////////////////////////////////// //source/////////////////////////////////// #ifndef MENU_H #define MENU_H #include <vector> using namespace std; #define ITEM_TEXT 1 #define ITEM_KEY 2 #define ITEM_BOOL 3 #define ITEM_INT 4 #define ITEM_FLOAT 5 #define ITEM_KEY_CHANGE 6 struct MENUITEM_INT { char name[71]; int value; }; struct MENUITEM { char name[71]; int key; int type; void *p; vector<MENUITEM_INT> IntItems; int IntIndex; struct MENUITEM_FLOAT { float min,max,aktual; } float_item; }; ////////// class Menu { public: int CreateVertexBufferForRectange(float left, float top, float right, float bottom, float alpha); void AddKeyChange(char* name, int key=-1, void* p=NULL); void AddBool(char* name, int key=-1, void* p=NULL, int value=0); void AddText(char* text); void AddKey(char* name, int key=-1, void* p=NULL); void AddInt(char* name, int key=-1, void* p=NULL); void AddIntItem(char* name, void* p); void AddIntSetIndex(int index); void AddFloat(char* name, int key, void* p, float min, float max, float aktual); void AddFloatComp(char* name, int key, void* p, float min, float max, float value); void ChangeSetting(float timeframe=0.02f); void Render(float timeframe=0.02); Menu(); int Init(Font *font); virtual ~Menu(); Font *f; vector<MENUITEM> items; int akt_item; POINT last_mouse_pos; LPDIRECT3DVERTEXBUFFER9 pvb_rectange; }; #endif Menu::Menu() { f = NULL; akt_item=0; pvb_rectange = NULL; } Menu::~Menu() { if(pvb_rectange!=NULL)pvb_rectange->Release(); } int Menu::Init(Font *font) { pvb_rectange = NULL; if(font==NULL)return 0; f = font; akt_item=0; if(!CreateVertexBufferForRectange(0,1,1,0,0.5f))return 0; return 1; } void Menu::Render(float timeframe) { POINT MousePoint; RECT WindowRect,ClientRect; GetCursorPos(&MousePoint); GetWindowRect(hWnd, &WindowRect); GetClientRect(hWnd, &ClientRect); int vyska = ClientRect.bottom; int sirka = ClientRect.right; int mouse_move=0; if( last_mouse_pos.x != MousePoint.x || last_mouse_pos.y != MousePoint.y) mouse_move=1; //if (fullscreen) // AdjustWindowRectEx(&ClientRect, WS_POPUP, FALSE, WS_EX_APPWINDOW); //else // AdjustWindowRectEx(&ClientRect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE); float xf = (screen_x_font/(float)sirka)*(MousePoint.x-WindowRect.left+ClientRect.left)/(float)11; float yf = (screen_y_font/(float)vyska)*(MousePoint.y-WindowRect.top+ClientRect.top)/16; int ydelta=1; int xdelta=1; int znakov=0; // max 70; int riadkov=0; // max 35 // y = screen_y_font - (y+1)*16; int maxNameLen=0; int maxExtLen=0; for( int i=0; i<items.size(); i++) { int len=0; if( items[i].type!=ITEM_INT) { len += strlen(items[i].name); if(len>maxNameLen)maxNameLen=len; } else { for(int j=0; j<items[i].IntItems.size(); j++) { if( strlen(items[i].IntItems[j].name)>len) len = strlen(items[i].IntItems[j].name); } if(len>maxNameLen)maxNameLen=len; } len=0; if( items[i].type==ITEM_BOOL )len+=7; // :_OFF_- = 7 else if( items[i].type==ITEM_KEY )len+=3; // :_- = 3 else if( items[i].type==ITEM_KEY_CHANGE )len+=3; // :_- = 3 else if( items[i].type==ITEM_INT ) { len+=3; // :_- = 3 if( items[i].p == NULL) len+=4; // _!!! = 4 } else if( items[i].type==ITEM_FLOAT )len+=11;// :_1.34567_- else len+=7; // :_!!!_! = 7 if(len>maxExtLen)maxExtLen = len; riadkov++; } znakov = maxNameLen+maxExtLen; if(znakov>70)znakov=70; xdelta = (70-znakov)/2+1; ydelta = (35-riadkov)/2+1; int x = (int)xf-xdelta; int y = (int)yf-ydelta; int akt_item_old = akt_item; if(mouse_move) { if(y>=0 && y<items.size() && x>=0 && x<znakov) akt_item=y; } else { if(keystate[DIK_DOWN]) { akt_item = (akt_item+1)%items.size(); keystate[DIK_DOWN]=0; } if(keystate[DIK_UP]) { akt_item--; if(akt_item<0)akt_item=items.size()-1; keystate[DIK_UP]=0; } } if( akt_item != akt_item_old ) { mousestate.rgbButtons[0]=0; keystate[DIK_RIGHT]=0; keystate[DIK_LEFT]=0; } if(items[akt_item].type==ITEM_BOOL) { if(mousestate.rgbButtons[0]) { if(items[akt_item].p!=NULL)*(int*)items[akt_item].p=!*(int*)items[akt_item].p; mousestate.rgbButtons[0]=0; } if(keystate[DIK_RIGHT]) { if(items[akt_item].p!=NULL)*(int*)items[akt_item].p=1; keystate[DIK_RIGHT]=0; } if(keystate[DIK_LEFT]) { if(items[akt_item].p!=NULL)*(int*)items[akt_item].p=0; keystate[DIK_LEFT]=0; } } else if(items[akt_item].type==ITEM_INT) { if(items[akt_item].IntItems.size()>0) { if(mousestate.rgbButtons[0] || keystate[DIK_RIGHT]) { items[akt_item].IntIndex = (items[akt_item].IntIndex+1)%items[akt_item].IntItems.size(); } if(keystate[DIK_LEFT]) { items[akt_item].IntIndex--; if(items[akt_item].IntIndex<0) items[akt_item].IntIndex = items[akt_item].IntItems.size()-1; } if(items[akt_item].p!=NULL) { *(int*)items[akt_item].p = items[akt_item].IntItems[items[akt_item].IntIndex].value; } } mousestate.rgbButtons[0]=0; keystate[DIK_RIGHT]=0; keystate[DIK_LEFT]=0; } else if(items[akt_item].type==ITEM_FLOAT) { float step=0.1f; if(keystate[DIK_LSHIFT] || keystate[DIK_RSHIFT])step=0.01f; if(mousestate.rgbButtons[0] && mouse_move) { items[akt_item].float_item.aktual+= (float)(MousePoint.x - last_mouse_pos.x)*step*0.03f; if(items[akt_item].float_item.aktual>1.0f)items[akt_item].float_item.aktual=1.f; if(items[akt_item].float_item.aktual<0.0f)items[akt_item].float_item.aktual=0.f; if(items[akt_item].p!=NULL) { *(float*)items[akt_item].p = items[akt_item].float_item.min + items[akt_item].float_item.aktual*(items[akt_item].float_item.max-items[akt_item].float_item.min); } } if(keystate[DIK_RIGHT]) { items[akt_item].float_item.aktual+=step*timeframe; if(items[akt_item].float_item.aktual>1.0f)items[akt_item].float_item.aktual=1.f; if(items[akt_item].p!=NULL) { *(float*)items[akt_item].p = items[akt_item].float_item.min + items[akt_item].float_item.aktual*(items[akt_item].float_item.max-items[akt_item].float_item.min); } } if(keystate[DIK_LEFT]) { items[akt_item].float_item.aktual-=step*timeframe; if(items[akt_item].float_item.aktual<0.0f)items[akt_item].float_item.aktual=0.f; if(items[akt_item].p!=NULL) { *(float*)items[akt_item].p = items[akt_item].float_item.min + items[akt_item].float_item.aktual*(items[akt_item].float_item.max-items[akt_item].float_item.min); } } } else if(items[akt_item].type==ITEM_KEY_CHANGE) { if(mousestate.rgbButtons[0]) { if(items[akt_item].p!=NULL) *(int*)items[akt_item].p=1; mousestate.rgbButtons[0]=0; } } for(int j=0x30; j<=0x39; j++) { if(keystate[j]) { items[akt_item].key = j; keystate[j]=0; } } int j; // for(j=0x41; j<=0x5A; j++) { if(j=='A' || j=='S' || j=='D' || j=='W' || j=='R')continue; if(keystate[j]) { items[akt_item].key = j; keystate[j]=0; } } if(keystate[DIK_BACK]) { items[akt_item].key = -1; keystate[DIK_BACK]=0; } f->Begin(); d3dDevice->SetRenderState(D3DRS_LIGHTING, 0); mat4 m; m.Translate(-5+xdelta*11,5+screen_y_font-(ydelta+riadkov+1)*16,0); m.Scale((xdelta+znakov+1)*11+5-xdelta*11, -5-screen_y_font+(ydelta+riadkov+1)*16-5+screen_y_font-(ydelta-1)*16,1); d3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*) m.m); d3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); d3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); d3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); d3dDevice->SetStreamSource( 0, pvb_rectange, 0, 3*sizeof(float)+sizeof(DWORD)); d3dDevice->SetFVF( D3DFVF_XYZ|D3DFVF_DIFFUSE ); d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); d3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR); d3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_SRCALPHA ); d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); d3dDevice->SetRenderState( D3DRS_LIGHTING, 1 ); int i; // for( i=0; i<items.size(); i++) { if(i==akt_item)f->SetColor(1,0,0,1); if(items[i].type==ITEM_TEXT) { f->Print( xdelta, i+ydelta, items[i].name, 0); } else if(items[i].type==ITEM_KEY || items[i].type==ITEM_KEY_CHANGE) { if(items[i].p!=NULL) { char text_keys[2]={0}; f->Print( xdelta, i+ydelta, items[i].name, 0); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print( xdelta+maxNameLen, i+ydelta, ":", 0); f->Print( xdelta+maxNameLen+2, i+ydelta, text_keys, 0); } else { f->Print( xdelta+maxNameLen, i+ydelta, ": !!! !", 0); } } else if(items[i].type==ITEM_BOOL) { if(items[i].p!=NULL) { char text_keys[2]={0}; f->Print( xdelta, i+ydelta, items[i].name, 0); if( *(int*)items[i].p )f->Print( xdelta+maxNameLen, i+ydelta, ": ON", 0); else f->Print( xdelta+maxNameLen, i+ydelta, ": OFF", 0); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print( xdelta+maxNameLen+6, i+ydelta, text_keys, 0); } else { f->Print( xdelta+maxNameLen, i+ydelta, ": !!! !", 0); } } else if(items[i].type==ITEM_INT) { char text_keys[2]={0}; if(items[i].IntItems.size()<=0)f->Print(xdelta, i+ydelta, items[i].name, 0); else f->Print( xdelta, i+ydelta, items[i].IntItems[items[i].IntIndex].name, 0); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print(xdelta+maxNameLen, i+ydelta, ":", 0); f->Print(xdelta+maxNameLen+2, i+ydelta, text_keys, 0); if(items[i].p==NULL)f->Print( xdelta+maxNameLen+4, i+ydelta, "!!!", 0); } else if(items[i].type==ITEM_FLOAT) { char text_keys[2]={0}; char text_float[50]; f->Print( xdelta, i+ydelta, items[i].name, 0); if(items[i].key==-1)text_keys[0]='-'; else text_keys[0]=items[i].key; f->Print( xdelta+maxNameLen+10, i+ydelta, text_keys, 0); float a = items[i].float_item.min+items[i].float_item.aktual*(items[i].float_item.max-items[i].float_item.min); _gcvt( (double)a, 4, text_float); f->Print( xdelta+maxNameLen, i+ydelta, ":", 0); f->Print( xdelta+maxNameLen+2, i+ydelta, text_float, 0); } f->SetColor(1,1,1,1); } for(i=0;i<znakov;i++){f->Print(xdelta+i,ydelta-1,"\x13",1);} //top for(i=0;i<znakov;i++){f->Print(xdelta+i,ydelta+riadkov,"\x19",1);} //botton for(i=0;i<riadkov;i++){f->Print(xdelta-1,ydelta+i,"\x15",1);} //left for(i=0;i<riadkov;i++){f->Print(xdelta+znakov,ydelta+i,"\x17",1);} //right f->Print(xdelta-1,ydelta-1,"\x12",1); //top and left f->Print(xdelta+znakov,ydelta-1,"\x14",1); //top and right f->Print(xdelta-1,ydelta+riadkov,"\x18",1); //botton and left f->Print(xdelta+znakov,ydelta+riadkov,"\x1A",1); //botton and right f->End(); last_mouse_pos = MousePoint; } void Menu::ChangeSetting( float timeframe) { for(int i=0; i<items.size(); i++) { if(items[i].key!=-1 ) { if(keystate[items[i].key]) { if(items[i].type==ITEM_BOOL) { if(items[i].p!=NULL) { *(int*)items[i].p=!*(int*)items[i].p; } } else if(items[i].type==ITEM_INT) { if(keystate[DIK_LSHIFT] || keystate[DIK_RSHIFT]) { items[i].IntIndex = (items[i].IntIndex-1); if(items[i].IntIndex<0)items[i].IntIndex = items[i].IntItems.size()-1; } else { items[i].IntIndex = (items[i].IntIndex+1)%items[i].IntItems.size(); } if(items[i].p!=NULL) { *(int*)items[i].p = items[i].IntItems[items[i].IntIndex].value; } } else if(items[i].type==ITEM_FLOAT) { if(keystate[DIK_LSHIFT] || keystate[DIK_RSHIFT])items[i].float_item.aktual-=0.1f*timeframe; else items[i].float_item.aktual+=0.1f*timeframe; if(items[i].float_item.aktual>1.0f)items[i].float_item.aktual=1.f; if(items[i].float_item.aktual<0.0f)items[i].float_item.aktual=0.f; if(items[i].p!=NULL) *(float*)items[i].p = items[i].float_item.min + items[i].float_item.aktual*(items[i].float_item.max-items[i].float_item.min); } else if(items[i].type==ITEM_KEY_CHANGE) { if(items[i].p!=NULL) *(int*)items[i].p=1; } } if(items[i].type==ITEM_KEY) { if(items[i].p!=NULL) { *(int*)items[i].p=keystate[items[i].key]; } } } } int i; // for( i=0; i<items.size(); i++) { if(items[i].key!=-1 && keystate[items[i].key]) { if(items[i].type==ITEM_BOOL || items[i].type==ITEM_INT || items[i].type==ITEM_KEY_CHANGE) { keystate[items[i].key]=0; } } } } void Menu::AddBool(char *name, int key, void *p, int value) { MENUITEM i; strncpy( i.name, name, 50); i.name[51]=NULL; i.key = key; i.p = p; if(i.p!=NULL)*(int*)i.p = value; i.type = ITEM_BOOL; items.push_back(i); } void Menu::AddText(char *text) { MENUITEM i; strncpy( i.name, text, 70); i.name[70]=NULL; i.key = -1; i.p = NULL; i.type = ITEM_TEXT; items.push_back(i); } void Menu::AddKey(char *name, int key, void* p) { MENUITEM i; strncpy( i.name, name, 50); i.name[50]=NULL; i.key = key; if(i.key!=-1)keystate[i.key]=0; i.p = p; if(i.p!=NULL)*(int*)i.p = 0; i.type = ITEM_KEY; items.push_back(i); } void Menu::AddInt(char *name, int key, void *p) { MENUITEM i; strncpy( i.name, name, 70); i.name[70]=NULL; i.key = key; i.p = p; i.type = ITEM_INT; i.IntIndex = 0; items.push_back(i); } void Menu::AddIntItem(char *name, void *p) { if(items.size()<=0)return; int index = items.size()-1; if(items[index].type!=ITEM_INT)return; MENUITEM_INT i; strncpy(i.name, name, 70); i.name[70]=NULL; if(p!=NULL)i.value = *(int*)p; else i.value=0; items[index].IntItems.push_back( i); } void Menu::AddFloat(char *name, int key, void *p, float min, float max, float aktual) { MENUITEM i; strncpy( i.name, name, 50); i.name[50]=NULL; i.key = key; i.p = p; i.type = ITEM_FLOAT; i.float_item.min = min; i.float_item.max = max; if( aktual<0) aktual=0; else if(aktual>1)aktual=1; i.float_item.aktual = aktual; items.push_back(i); } void Menu::AddFloatComp(char *name, int key, void *p, float min, float max, float value) { float aktual = (value-min)/(max-min); if(p!=NULL)*(float*)p=value; AddFloat( name, key, p, min, max, aktual); } void Menu::AddIntSetIndex(int index) { if(items.size()<=0)return; int i = items.size()-1; if(items[i].type!=ITEM_INT)return; if(index<0)index=0; if(index>=items[i].IntItems.size()) index = items[i].IntItems.size()-1; items[i].IntIndex = index; *(int*)items[i].p = items[i].IntItems[index].value; } void Menu::AddKeyChange(char *name, int key, void *p) { MENUITEM i; strncpy( i.name, name, 50); i.name[50]=NULL; i.key = key; if(i.key!=-1)keystate[i.key]=0; i.p = p; if(i.p!=NULL)*(int*)i.p = 0; i.type = ITEM_KEY_CHANGE; items.push_back(i); } int Menu::CreateVertexBufferForRectange(float left, float top, float right, float bottom, float alpha) { int size_of_custom_vertex = 3*sizeof(float)+sizeof(DWORD); if( FAILED( d3dDevice->CreateVertexBuffer( 4*size_of_custom_vertex,D3DUSAGE_WRITEONLY, D3DFVF_XYZ|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT, &pvb_rectange, NULL)))return 0; void* p1; if( FAILED( pvb_rectange->Lock( 0, 4*size_of_custom_vertex, (VOID**)&p1, 0 ) ) )return 0; ((float*)p1)[0*4+0] = left; ((float*)p1)[0*4+1] = bottom; ((float*)p1)[0*4+2] = 0; ((DWORD*)p1)[0*4+3] = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,alpha); ((float*)p1)[1*4+0] = right; ((float*)p1)[1*4+1] = bottom; ((float*)p1)[1*4+2] = 0; ((DWORD*)p1)[1*4+3] = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,alpha); ((float*)p1)[2*4+0] = left; ((float*)p1)[2*4+1] = top; ((float*)p1)[2*4+2] = 0; ((DWORD*)p1)[2*4+3] = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,alpha); ((float*)p1)[3*4+0] = right; ((float*)p1)[3*4+1] = top; ((float*)p1)[3*4+2] = 0; ((DWORD*)p1)[3*4+3] = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,alpha); pvb_rectange->Unlock(); return 1; } ////////////////////////////////// Please help me to figure out why I am getting link errors from those structs. Remember, this is not my whole project only the part that is giving me the struct lnk 2019 errors.

Share this post


Link to post
Share on other sites
Could be one of a few things.

Are you trying to run a release build? If so, check that you don't have _DEBUG defined somewhere if your code/project release settings.

If that's not the case, try ignoring the library msvcrt.lib (also done in project settings)

Still doesn't work? Make sure that you have all the correct debug libraries linked (or release libraries linked for release mode)

Other than that, I'm not sure.

Share this post


Link to post
Share on other sites
Not so much about your linker errors, but some helpful advice:

1) Post your code in between [ source ] and [ /source ] tags (without the spaces). Especially large code blocks like this.

2) Don't put using statements in header files. It's just begging for name conflicts.

Share this post


Link to post
Share on other sites
This is due to the wrong runtime library being selected. In "Project->Properties->C/C++->Code Generation" make sure "Runtime Library" is set to a debug version ("Multi-Threaded Debug DLL" or "Multi-Threaded Debug").

Or, along the lines of what Ehrys said, make sure NDEBUG is defined.


jfl.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this