visual studio - How to store data from resource pointer to a static memory buffer in C++? -


i have loaded a.dat file in resource in vc++ project in visual studio told in documentation.

now in main code, want load data static memory buffer resource pointer:

hrsrc myresource = ::findresource(null, makeintresource(idr_rcdata1), rt_rcdata); unsigned int myresourcesize = ::sizeofresource(null, myresource); hglobal myresourcedata = ::loadresource(null, myresource); void* pmybinarydata = ::lockresource(myresourcedata); 

now i'm stucked on how create static memory buffer , store data pmybinarydata pointer.

can solved please! in advance.

you have information need: size of data (myresourcesize), , contents of resource (pmybinarydata), can create buffer , copy contents it:

void *buffer = malloc(myresourcesize); memcpy(buffer, pmybinarydata, myresourcesize); 

buffer holds copy of bytes making resource, , can keep long need - can call ::unlockresource(myresourcedata); without affecting buffer. don't forget @ stage free(buffer); though - unless need life of program.

but if static mean static, pre-allocated array, need pre-allocate largest possible size front:

#define max_resource_size 65536 // there no maximum size - you'll need pick 1 static char buffer[max_resource_size]; ... if (myresourcesize>max_resource_size) {     error("resource big!"); } // if memcpy(buffer, pmybinarydata, myresourcesize); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -