* This function will load a module from a file * * @param path the full path of application module * * @return the module object */
| 241 | * @return the module object |
| 242 | */ |
| 243 | rt_module_t rt_module_open(const char *path) |
| 244 | { |
| 245 | struct dfs_filesystem *fs; |
| 246 | appentry_t fptr; |
| 247 | HINSTANCE hinstlib; |
| 248 | rt_module_t module; |
| 249 | |
| 250 | char * winpath = RT_NULL; |
| 251 | char * name = RT_NULL; |
| 252 | |
| 253 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 254 | |
| 255 | /* check parameters */ |
| 256 | RT_ASSERT(path != RT_NULL); |
| 257 | |
| 258 | /* app module should only in DFS_WIN32 */ |
| 259 | fs = dfs_filesystem_lookup(path); |
| 260 | if ((fs == RT_NULL) || (strcmp(fs->ops->name,"wdir") != 0)) |
| 261 | { |
| 262 | rt_kprintf("invalid path: %s\n", path); |
| 263 | return RT_NULL; |
| 264 | } |
| 265 | |
| 266 | /* change path */ |
| 267 | // len = strlen(path+1); |
| 268 | if ((winpath = dfs_win32_dirdup((char *)path)) == RT_NULL) |
| 269 | { |
| 270 | rt_kprintf("out of memory, exit"); |
| 271 | return RT_NULL; |
| 272 | } |
| 273 | |
| 274 | hinstlib = LoadLibrary(winpath); |
| 275 | if (hinstlib == NULL) |
| 276 | { |
| 277 | rt_kprintf("error: unable to open %s\n", winpath); |
| 278 | return RT_NULL; |
| 279 | } |
| 280 | |
| 281 | fptr = (appentry_t)GetProcAddress(hinstlib, "main"); |
| 282 | if (fptr == NULL) |
| 283 | { |
| 284 | rt_kprintf("error: unable to find function in %s\n", winpath); |
| 285 | FreeLibrary(hinstlib); |
| 286 | return RT_NULL; |
| 287 | } |
| 288 | |
| 289 | /* get the name of the module */ |
| 290 | name = _module_name(path); |
| 291 | |
| 292 | /* allocate module */ |
| 293 | module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name); |
| 294 | if (!module) return RT_NULL; |
| 295 | |
| 296 | module->nref = 0; |
| 297 | module->module_entry = fptr; |
| 298 | |
| 299 | /* init module object container */ |
| 300 | rt_module_init_object_container(module); |
nothing calls this directly
no test coverage detected