error LNK2019: unresolved external symbol adobe Flash source engine - c++

Iam modding in the source Engine and iam trying to add adobe Flash into it
i have already included header files and the libs from Microsoft DirectX SDK (June 2010) in visual studio 2010 but when Compiling the project it give me errors
1>FlashManager.obj : error LNK2019: unresolved external symbol _D3DXCreateSprite#8 referenced in function "public: bool __thiscall FlashManager::RecreateTargets(struct IDirect3DDevice9 *)" (?RecreateTargets#FlashManager##QAE_NPAUIDirect3DDevice9###Z)
1>FlashManager.obj : error LNK2019: unresolved external symbol _D3DXMatrixTransformation2D#28 referenced in function "public: void __thiscall FlashManager::SceneDataHook(void)" (?SceneDataHook#FlashManager##QAEXXZ)
1>FlashManager.obj : error LNK2019: unresolved external symbol "struct IFlashDX * __cdecl GetFlashToDirectXInstance(void)" (?GetFlashToDirectXInstance##YAPAUIFlashDX##XZ) referenced in function "public: __thiscall FlashManager::FlashManager(void)" (??0FlashManager##QAE#XZ)
1>.\Release_sdk\Client.dll : fatal error LNK1120: 3 unresolved externals
How Can i fix it
linked every thing
The code
bool FlashManager::RecreateTargets(IDirect3DDevice9* pD3DDevice)
{
HRESULT hr;
int movieIndex = GetPlayingMovieIndex();
int newWidth = -1, newHeight = -1;
if (movieIndex > -1)
{
newWidth = m_movieArray[movieIndex].GetWidth();
newHeight = m_movieArray[movieIndex].GetHeight();
}
else
{
newWidth = w;
newHeight = h;
}
hr = pD3DDevice->CreateTexture(newWidth, newHeight, 1, 0, transparency_mode ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_Texture, NULL);
if (FAILED(hr))
return false;
D3DXCreateSprite(pD3DDevice, &Sprite); //the problem
g_pD3DDevice = pD3DDevice;
if (m_flashPlayer)
m_flashPlayer->ResizePlayer(newWidth, newHeight);
for (int i = 0; i < num_textures_in_rotation; ++i)
{
hr = pD3DDevice->CreateTexture(newWidth, newHeight, 1, 0,
transparency_mode ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &g_texturesRotation[i], NULL);
if (FAILED(hr))
return false;
}
recreatedTargets = true;
return true;
}
Link error 2
D3DXMatrixTransformation2D(&Mat, NULL, 0, &Scaling, NULL, 0, &Translation); // The problem
The Last link error
FlashManager::FlashManager()
{
engine->GetScreenSize(w, h);
// Flash init
m_flashDX = GetFlashToDirectXInstance(); //the problem
m_flashPlayer = m_flashDX->CreatePlayer(w, h);
if (!m_flashPlayer)
{
MessageBox(NULL, "Flash Player failed to initialize.", "Error", MB_OK);
abort();
}
m_playerASI = new ASInterface(m_flashPlayer);

Related

FltRegisterFilter referenced in Function DriverEntry in filter.obj

Basically I am trying create a simple FileSystem MiniFilter Driver where I can modify a notepad file from writing. Following this tutorial. So I created a project in visual studio which is type Filter Driver: NDIS. here is the full code:
/*++
Module Name:
Filter.c
Abstract:
Sample NDIS Lightweight filter driver
--*/
#include "precomp.h"
PFLT_FILTER FilterHandle = NULL;
NTSTATUS MiniUnload(FLT_FILTER_UNLOAD_FLAGS Flags);
FLT_POSTOP_CALLBACK_STATUS MiniPostCreate(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext, FLT_POST_OPERATION_FLAGS flags);
FLT_PREOP_CALLBACK_STATUS MiniPreCreate(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext);
FLT_PREOP_CALLBACK_STATUS MiniPreWrite(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext);
const FLT_OPERATION_REGISTRATION Callbacks[] = {
{IRP_MJ_CREATE,0,MiniPreCreate,MiniPostCreate},
{IRP_MJ_WRITE,0,MiniPreCreate,NULL},
{IRP_MJ_OPERATION_END}
};
const FLT_REGISTRATION FilterRegistration = {
sizeof(FLT_REGISTRATION),
FLT_REGISTRATION_VERSION,
0,
NULL,
Callbacks,
MiniUnload,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
NTSTATUS MiniUnload(FLT_FILTER_UNLOAD_FLAGS Flags) {
KdPrint(("driver unload \r\n"));
FltUnregisterFilter(FilterHandle);
return STATUS_SUCCESS;
}
FLT_POSTOP_CALLBACK_STATUS MiniPostCreate(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext, FLT_POST_OPERATION_FLAGS flags) {
KdPrint(("Post Create is running \r\n"));
return FLT_POSTOP_FINISHED_PROCESSING;
}
FLT_PREOP_CALLBACK_STATUS MiniPreCreate(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext) {
PFLT_FILE_NAME_INFORMATION FileNameInfo;
NTSTATUS status;
WCHAR Name[300] = { 0 };
status = FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &FileNameInfo);
if (NT_SUCCESS(status)) {
status = FltParseFileNameInformation(FileNameInfo);
if (NT_SUCCESS(status)) {
if (FileNameInfo->Name.MaximumLength < 260) {
RtlCopyMemory(Name, FileNameInfo->Name.Buffer, FileNameInfo->Name.MaximumLength);
KdPrint(("CreateFile: %ws \r\n", Name));
}
}
FltReleaseFileNameInformation(FileNameInfo);
}
return FLT_PREOP_SUCCESS_WITH_CALLBACK;
}
FLT_PREOP_CALLBACK_STATUS MiniPreWrite(PFLT_CALLBACK_DATA Data, PCFLT_RELATED_OBJECTS FltObjects, PVOID* CompletionContext) {
PFLT_FILE_NAME_INFORMATION FileNameInfo;
NTSTATUS status;
WCHAR Name[300] = { 0 };
status = FltGetFileNameInformation(Data, FLT_FILE_NAME_NORMALIZED | FLT_FILE_NAME_QUERY_DEFAULT, &FileNameInfo);
if (NT_SUCCESS(status)) {
status = FltParseFileNameInformation(FileNameInfo);
if (NT_SUCCESS(status)) {
if (FileNameInfo->Name.MaximumLength < 260) {
RtlCopyMemory(Name, FileNameInfo->Name.Buffer, FileNameInfo->Name.MaximumLength);
_wcsupr(Name);
if (wcsstr(Name, L"OPENME.TXT") != NULL) {
KdPrint(("Write File: %ws Blocked \r\n", Name));
Data->IoStatus.Status = STATUS_INVALID_PARAMETER;
Data->IoStatus.Information = 0;
FltReleaseFileNameInformation(FileNameInfo);
return FLT_PREOP_COMPLETE;
}
KdPrint(("CreateFile: %ws \r\n", Name));
}
}
FltReleaseFileNameInformation(FileNameInfo);
}
return FLT_PREOP_SUCCESS_WITH_CALLBACK;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
NTSTATUS status;
status = FltRegisterFilter(DriverObject, &FilterRegistration, &FilterHandle);
if (NT_SUCCESS(status)) {
status = FltStartFiltering(FilterHandle);
if (!NT_SUCCESS(status)) {
FltUnregisterFilter(FilterHandle);
}
}
return status;
}
The header files have been to precomp.h as below:
#pragma warning(disable:4201) //nonstandard extension used : nameless struct/union
#pragma warning(disable:4100)
#include <fltKernel.h>
#include <dontuse.h>
#include <suppress.h>
#include <ndis.h>
#include <filteruser.h>
#include <ntddk.h>
#include "flt_dbg.h"
#include "filter.h"
Everything else is default.
Project configuration is Active(x64) under properties.
With all of that I am getting below errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol FltGetFileNameInformation referenced in function MiniPreCreate default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Warning 1324 [Version] section should specify PnpLockdown=1 to prevent external apps from modifying installed driver files. default C:\Users\Abdul\source\repos\default\default\default.inf 8
Error LNK2019 unresolved external symbol FltRegisterFilter referenced in function DriverEntry default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Error LNK2019 unresolved external symbol FltUnregisterFilter referenced in function MiniUnload default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Error LNK2019 unresolved external symbol FltStartFiltering referenced in function DriverEntry default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Error LNK2019 unresolved external symbol FltReleaseFileNameInformation referenced in function MiniPreCreate default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Error LNK2019 unresolved external symbol FltParseFileNameInformation referenced in function MiniPreCreate default C:\Users\Abdul\source\repos\default\default\filter.obj 1
Error LNK2001 unresolved external symbol FilterDriverHandle default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK2001 unresolved external symbol FilterDriverObject default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK2001 unresolved external symbol NdisFilterDeviceHandle default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK2001 unresolved external symbol NdisDeviceObject default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK2001 unresolved external symbol FilterListLock default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK2001 unresolved external symbol FilterModuleList default C:\Users\Abdul\source\repos\default\default\device.obj 1
Error LNK1120 12 unresolved externals default C:\Users\Abdul\source\repos\default\x64\Debug\default.sys 1
Can Anyone guide on what am I doing wrong?
I ran into the same issue. For me, the problem was that the mini-filter template was not showing in the templates listing for new projects and so I had to create it from scratch and I inevitably missed something. After cross-checking the linker options against the minifilter projects provided by Microsoft as reference (check here) I realized that fltMgr.lib has to be specifically provided to the linker. In order to do that right-click on the project in the "Solution Explorer" left pane. Then go to Properties->Linker->Input->Additional Dependencies. Add $(DDK_LIB_PATH)\fltMgr.lib to the list of additional dependencies and rebuild your project!
I hope this does it for you, but like the Microsoft documentation points out LNK2019 can be caused by lots of other problems with your configuration.

C++ WinHTTP library generating symbol errors [duplicate]

Trying to compile a sample http class with the SDK, and getting some strange link errors... I am sure its something to do with a missing option, or directory...
I am no expert in c++ as you can see, but looking for any assistance.
I included my sample class. I also did install the Windows SDK. If you need any other information about my setups or anything, please ask. I'd prefer someone point me to a working WinHttp SDK sample project.
//START OF utils.cpp
#pragma once
#include "stdafx.h"
class http
{
public:
http();
~http();
std::string getText();
};
//END OF utils.cpp
//START OF utils.cpp
#include "stdafx.h"
#include "utils.h"
http::http()
{
}
http::~http()
{
}
std::string http::getText()
{
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"WinHTTP Example/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0 );
// Specify an HTTP server.
if( hSession )
hConnect = WinHttpConnect( hSession, L"www.microsoft.com",
INTERNET_DEFAULT_HTTPS_PORT, 0 );
// Create an HTTP request handle.
if( hConnect )
hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE );
// Send a request.
if( hRequest )
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0,
0, 0 );
// End the request.
if( bResults )
bResults = WinHttpReceiveResponse( hRequest, NULL );
// Keep checking for data until there is nothing left.
if( bResults )
{
do
{
// Check for available data.
dwSize = 0;
if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
printf( "Error %u in WinHttpQueryDataAvailable.\n",
GetLastError( ) );
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize+1];
if( !pszOutBuffer )
{
printf( "Out of memory\n" );
dwSize=0;
}
else
{
// Read the data.
ZeroMemory( pszOutBuffer, dwSize+1 );
if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded ) )
printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
else
printf( "%s", pszOutBuffer );
// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}
} while( dwSize > 0 );
}
// Report any errors.
if( !bResults )
printf( "Error %d has occurred.\n", GetLastError( ) );
// Close any open handles.
if( hRequest ) WinHttpCloseHandle( hRequest );
if( hConnect ) WinHttpCloseHandle( hConnect );
if( hSession ) WinHttpCloseHandle( hSession );
return "";
}
//END OF utils.cpp
1>------ Build started: Project: winagent, Configuration: Debug Win32 ------
1>Compiling...
1>utils.cpp
1>Linking...
1> Creating library C:\winagent\Debug\winagent.lib and object C:\winagent\Debug\winagent.exp
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle#4 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpReadData#16 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryDataAvailable#8 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse#8 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest#28 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest#28 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect#16 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>utils.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen#20 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall http::getText(void)" (?getText#http##QAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>C:\winagent\Debug\winagent.exe : fatal error LNK1120: 8 unresolved externals
1>Build log was saved at "file://c:\winagent\Debug\BuildLog.htm"
1>winagent - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you check the MSDN reference for the WinHttp* functions you will see that you need to link with the library Winhttp.lib.
Open the project settings, select the linker options then 'input' and add WinHttp.lib to the 'Additional Dependencies' list.
Or you could put
#pragma comment(lib, "winhttp.lib")
(as previously mentioned) in your source code.
You need to link to winhttp.lib
Change the project settings or add this line to your .cpp file
#pragma comment(lib, "winhttp")
You've not added the WinHttp library to your link list.
Make sure you are linking with Winhttp.lib.

How can I download the HTML contents of a webpage using C++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
Here is my code
#include <iostream>
#include <Windows.h>
#include <WinInet.h>
using namespace std;
int main()
{
HINTERNET hSession, hURL;
char* Buffer = new char[1024];
DWORD BufferLen, BytesWritten;
HANDLE FileHandle;
hSession = InternetOpenA(NULL, 0, NULL, NULL, 0);
hURL = InternetOpenUrlA(hSession, "http://www.google.co.uk", NULL, 0, 0, 0);
FileHandle = CreateFileA("C:\\temp.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
BytesWritten = 0;
do
{
InternetReadFile(hURL, Buffer, 1024, &BufferLen);
WriteFile(FileHandle, Buffer, BufferLen, &BytesWritten, NULL);
} while (BufferLen != 0);
CloseHandle(FileHandle);
InternetCloseHandle(hURL);
InternetCloseHandle(hSession);
ShellExecuteA(0, "open", "C:\\temp.txt", NULL, NULL, 1);
cout << "Operation complete!";
system("PAUSE");
return 0;
}
Here are the errors I am encountering
error LNK2019: unresolved external symbol __imp__InternetOpenA#20 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetCloseHandle#4 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetOpenUrlA#24 referenced in function _main
error LNK2019: unresolved external symbol __imp__InternetReadFile#16 referenced in function _main
I don't understand where I am going wrong. I have imported Wininet.h and Windows.h. Why is it still having trouble locating these functions? Regards.
What you have done is include the header file, but not linked to the actual code which implements it.
Include Wininet.lib in your project.
Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies

error: LNK1120: 9 unresolved externals

I'm trying to convert a bmp image to a png one with this code:
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_DEPRECATE
#include <png.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
void GetDesktopResolution(int& horizontal, int& vertical)
{
RECT desktop;
// Get a handle to the desktop window
const HWND hDesktop = GetDesktopWindow();
// Get the size of screen to the variable desktop
GetWindowRect(hDesktop, &desktop);
// The top left corner will have coordinates (0,0)
// and the bottom right corner will have coordinates
// (horizontal, vertical)
horizontal = desktop.right;
vertical = desktop.bottom;
}
typedef struct _RGBPixel {
uint8_t blue;
uint8_t green;
uint8_t red;
} RGBPixel;
/* Structure for containing decompressed bitmaps. */
typedef struct _RGBBitmap {
RGBPixel *pixels;
size_t width;
size_t height;
size_t bytewidth;
uint8_t bytes_per_pixel;
} RGBBitmap;
/* Returns pixel of bitmap at given point. */
#define RGBPixelAtPoint(image, x, y) \
*(((image)->pixels) + (((image)->bytewidth * (y)) \
+ ((x) * (image)->bytes_per_pixel)))
/* Attempts to save PNG to file; returns 0 on success, non-zero on error. */
int save_png_to_file(RGBBitmap *bitmap, const char *path)
{
FILE *fp = fopen(path, "wb");
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
size_t x, y;
png_uint_32 bytes_per_row;
png_byte **row_pointers = NULL;
if (fp == NULL) return -1;
/* Initialize the write struct. */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(fp);
return -1;
}
/* Initialize the info struct. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return -1;
}
/* Set up error handling. */
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return -1;
}
/* Set image attributes. */
png_set_IHDR(png_ptr,
info_ptr,
bitmap->width,
bitmap->height,
8,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
/* Initialize rows of PNG. */
bytes_per_row = bitmap->width * bitmap->bytes_per_pixel;
png_malloc(png_ptr, bitmap->height * sizeof(png_byte *));
for (y = 0; y < bitmap->height; ++y) {
uint8_t *row = (uint8_t *)png_malloc(png_ptr, sizeof(uint8_t)* bitmap->bytes_per_pixel);
row_pointers[y] = (png_byte *)row;
for (x = 0; x < bitmap->width; ++x) {
RGBPixel color = RGBPixelAtPoint(bitmap, x, y);
*row++ = color.red;
*row++ = color.green;
*row++ = color.blue;
}
}
/* Actually write the image data. */
png_init_io(png_ptr, fp);
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
/* Cleanup. */
for (y = 0; y < bitmap->height; y++) {
png_free(png_ptr, row_pointers[y]);
}
png_free(png_ptr, row_pointers);
/* Finish writing. */
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 0;
}
int main()
{
RGBBitmap rgbbitmap;
int w, h;
GetDesktopResolution(w, h);
rgbbitmap.height = h;
rgbbitmap.width = w;
rgbbitmap.bytes_per_pixel = 1;
rgbbitmap.bytewidth = w / 100;
RGBPixel rgbpixel;
rgbpixel.blue = 100;
rgbpixel.green = 100;
rgbpixel.red = 100;
rgbbitmap.pixels = &rgbpixel;
save_png_to_file(&rgbbitmap, "abc.bmp");
return 0;
}
Executing this code triggers these errors :
LNK1120: 9 unresolved externals
LNK2019: unresolved external symbol _png_create_info_struct referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_create_write_struct referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_destroy_write_struct referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_free referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_init_io referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_malloc referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_set_IHDR referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_set_rows referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
LNK2019: unresolved external symbol _png_write_png referenced in function "int __cdecl save_png_to_file(struct _RGBBitmap *,char const *)" (?save_png_to_file##YAHPAU_RGBBitmap##PBD#Z)
I'm not able to find how to fix these errors. Any brilliant suggestion, please?
I'm currently using Visual Studio Ultimate 2013 on a Windows 7 SP1 plateform.
Thanks a lot!
I think, you didn't linked your libraries, just included headers. This question anwers how you do it...
If not, there is plently of what can happen:
you are trying to call those functions with bad parameters
you included bad header file
you have mixed libraries or you are trying to link MinGW, VS2012/VS2012 compiled library to VS2013 compiler, since i don't know if they are compatible...
You can try to download png library, create VS2012 project and try to compile it. When you do, you should absolutely have no problems while linking...

error LNK2005 already defined - Compiler error when building after running

I'm trying to follow Riemer's DirectX with C++ tutorial.
I have made a few changes, for example here I have made my InitializeDevice() function in a separate file (tdirect.cpp / tdirect.h).
When I press F5 to compile and run, the program works perfectly. But when I make a change to a value (e.g. 0xff00ffff to 0xff0000ff - cyan to blue) without choosing the "Rebuild" option I get a stream of errors in my console which prevent me from compiling the program. This is pretty annoying as you can imagine. It's as if it's compiling tdirect.cpp twice.
Here's the source code of tdirect.cpp, tdirect.h, and the relevant part from main.cpp (tdirect.h is only included from main.cpp, and basicvertex.h is only included from tdirect.cpp)
tdirect.cpp:
#include "tdirect.h"
#include "basicvertex.h"
IDirect3D9 *pD3D;
D3DPRESENT_PARAMETERS D3DParams;
LPDIRECT3DDEVICE9 InitializeDevice(HWND Wnd)
{
pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == NULL)
{
MessageBox(Wnd, "DirectX is not installed.", "No DirectX!", MB_OK);
return NULL;
}
ZeroMemory(&D3DParams, sizeof(D3DPRESENT_PARAMETERS));
D3DParams.Windowed = TRUE;
D3DParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DParams.BackBufferFormat = D3DFMT_UNKNOWN;
LPDIRECT3DDEVICE9 pDevice;
if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &D3DParams, &pDevice)))
{
if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, Wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3DParams, &pDevice)))
{
MessageBox(Wnd, "Failed to create reference device.", "No software device!", MB_OK);
}
else {
MessageBox(Wnd, "Falling back to software mode.", "No hardware device!", MB_OK);
}
}
return pDevice;
}
LPDIRECT3DVERTEXBUFFER9 vBuffer;
void Init(LPDIRECT3DDEVICE9 pDevice)
{
BASICVERTEX Vertices[3];
Vertices[0].x = 150;
Vertices[0].y = 100;
Vertices[0].weight = 1;
Vertices[0].colour = 0xffff0000;
Vertices[1].x = 350;
Vertices[1].y = 100;
Vertices[1].weight = 1;
Vertices[1].colour = 0xff00ff00;
Vertices[2].x = 250;
Vertices[2].y = 300;
Vertices[2].weight = 1;
Vertices[2].colour = 0xff00ffff;
if (FAILED(pDevice->CreateVertexBuffer(sizeof(BASICVERTEX)*3, 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vBuffer, NULL)))
{
MessageBox(NULL, "Failed to create vertex buffer", "Fail", MB_OK);
}
else {
void* pVertices;
if (FAILED(vBuffer->Lock(0, sizeof(BASICVERTEX)*3, (void**)&pVertices, 0)))
{
MessageBox(NULL, "Failed to lock vertex buffer", "Fail", MB_OK);
}
else {
memcpy(pVertices, Vertices, sizeof(BASICVERTEX)*3);
vBuffer->Unlock();
}
}
}
void DrawScene(LPDIRECT3DDEVICE9 pDevice)
{
pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
pDevice->BeginScene();
pDevice->SetStreamSource(0, vBuffer, 0, sizeof(BASICVERTEX));
pDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
pDevice->EndScene();
pDevice->Present(NULL, NULL, NULL, NULL);
}
tdirect.h:
#pragma once
#include <Windows.h>
main.cpp include part:
#include <Windows.h>
#include "dxheader.h"
#include "tdirect.cpp"
Compiler Errors:
1>Debug\tdirect.obj : warning LNK4042: object specified more than once; extras ignored
1>main.obj : error LNK2005: "struct IDirect3DDevice9 * __cdecl InitializeDevice(struct HWND__ *)" (?InitializeDevice##YAPAUIDirect3DDevice9##PAUHWND__###Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "void __cdecl Init(struct IDirect3DDevice9 *)" (?Init##YAXPAUIDirect3DDevice9###Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "void __cdecl DrawScene(struct IDirect3DDevice9 *)" (?DrawScene##YAXPAUIDirect3DDevice9###Z) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct IDirect3DVertexBuffer9 * vBuffer" (?vBuffer##3PAUIDirect3DVertexBuffer9##A) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct _D3DPRESENT_PARAMETERS_ D3DParams" (?D3DParams##3U_D3DPRESENT_PARAMETERS_##A) already defined in tdirect.obj
1>main.obj : error LNK2005: "struct IDirect3D9 * pD3D" (?pD3D##3PAUIDirect3D9##A) already defined in tdirect.obj
1>C:\Users\me\Documents\Visual Studio 2010\Projects\DirectX\Debug\DXStuff.exe : fatal error LNK1169: one or more multiply defined symbols found
Thanks in advance :)
You're including an implementation file from your main.cpp, so it's adding the functions in again. You can't do this:
#include "tdirect.cpp"
Instead you need to create a header file with the function prototypes so you can reference them...
Do you have these defined in your "tdirect.h" (this is what main.cpp should be including)?
LPDIRECT3DDEVICE9 InitializeDevice(HWND Wnd);
etc...